mirror of https://github.com/pyodide/pyodide.git
Replace uglifyjs with terser (#1895)
This commit is contained in:
parent
4c61ce980d
commit
35921b7a15
|
@ -35,7 +35,6 @@ RUN ln -s ../lib/node_modules/npm/bin/npm-cli.js /usr/local/bin/npm \
|
||||||
|
|
||||||
RUN npm install -g \
|
RUN npm install -g \
|
||||||
jsdoc \
|
jsdoc \
|
||||||
uglify-js \
|
|
||||||
prettier \
|
prettier \
|
||||||
rollup \
|
rollup \
|
||||||
rollup-plugin-terser
|
rollup-plugin-terser
|
||||||
|
|
|
@ -63,6 +63,23 @@ class BashRunnerWithSharedEnvironment:
|
||||||
self._fd_write = None
|
self._fd_write = None
|
||||||
|
|
||||||
|
|
||||||
|
def _have_terser():
|
||||||
|
try:
|
||||||
|
# Check npm exists and terser is installed locally
|
||||||
|
subprocess.run(
|
||||||
|
[
|
||||||
|
"npm",
|
||||||
|
"list",
|
||||||
|
"terser",
|
||||||
|
],
|
||||||
|
stdout=subprocess.DEVNULL,
|
||||||
|
)
|
||||||
|
except subprocess.CalledProcessError:
|
||||||
|
return False
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
def check_checksum(path: Path, pkg: Dict[str, Any]):
|
def check_checksum(path: Path, pkg: Dict[str, Any]):
|
||||||
"""
|
"""
|
||||||
Checks that a tarball matches the checksum in the package metadata.
|
Checks that a tarball matches the checksum in the package metadata.
|
||||||
|
@ -281,7 +298,9 @@ def unvendor_tests(install_prefix: Path, test_install_prefix: Path) -> int:
|
||||||
return n_moved
|
return n_moved
|
||||||
|
|
||||||
|
|
||||||
def package_files(buildpath: Path, srcpath: Path, pkg: Dict[str, Any]) -> None:
|
def package_files(
|
||||||
|
buildpath: Path, srcpath: Path, pkg: Dict[str, Any], compress: bool = False
|
||||||
|
) -> None:
|
||||||
"""Package the installation folder into .data and .js files
|
"""Package the installation folder into .data and .js files
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
|
@ -324,10 +343,19 @@ def package_files(buildpath: Path, srcpath: Path, pkg: Dict[str, Any]) -> None:
|
||||||
cwd=buildpath,
|
cwd=buildpath,
|
||||||
check=True,
|
check=True,
|
||||||
)
|
)
|
||||||
subprocess.run(
|
|
||||||
["uglifyjs", buildpath / (name + ".js"), "-o", buildpath / (name + ".js")],
|
if compress:
|
||||||
check=True,
|
subprocess.run(
|
||||||
)
|
[
|
||||||
|
"npx",
|
||||||
|
"--no-install",
|
||||||
|
"terser",
|
||||||
|
buildpath / (name + ".js"),
|
||||||
|
"-o",
|
||||||
|
buildpath / (name + ".js"),
|
||||||
|
],
|
||||||
|
check=True,
|
||||||
|
)
|
||||||
|
|
||||||
# Package tests
|
# Package tests
|
||||||
if n_unvendored > 0:
|
if n_unvendored > 0:
|
||||||
|
@ -342,15 +370,19 @@ def package_files(buildpath: Path, srcpath: Path, pkg: Dict[str, Any]) -> None:
|
||||||
cwd=buildpath,
|
cwd=buildpath,
|
||||||
check=True,
|
check=True,
|
||||||
)
|
)
|
||||||
subprocess.run(
|
|
||||||
[
|
if compress:
|
||||||
"uglifyjs",
|
subprocess.run(
|
||||||
buildpath / (name + "-tests.js"),
|
[
|
||||||
"-o",
|
"npx",
|
||||||
buildpath / (name + "-tests.js"),
|
"--no-install",
|
||||||
],
|
"terser",
|
||||||
check=True,
|
buildpath / (name + "-tests.js"),
|
||||||
)
|
"-o",
|
||||||
|
buildpath / (name + "-tests.js"),
|
||||||
|
],
|
||||||
|
check=True,
|
||||||
|
)
|
||||||
|
|
||||||
with open(buildpath / ".packaged", "wb") as fd:
|
with open(buildpath / ".packaged", "wb") as fd:
|
||||||
fd.write(b"\n")
|
fd.write(b"\n")
|
||||||
|
@ -428,7 +460,7 @@ def build_package(path: Path, args):
|
||||||
# i.e. they need package running, but not compile
|
# i.e. they need package running, but not compile
|
||||||
if not pkg.get("build", {}).get("sharedlibrary"):
|
if not pkg.get("build", {}).get("sharedlibrary"):
|
||||||
compile(path, srcpath, pkg, args, bash_runner)
|
compile(path, srcpath, pkg, args, bash_runner)
|
||||||
package_files(buildpath, srcpath, pkg)
|
package_files(buildpath, srcpath, pkg, compress=args.compress_package)
|
||||||
finally:
|
finally:
|
||||||
bash_runner.close()
|
bash_runner.close()
|
||||||
os.chdir(orig_path)
|
os.chdir(orig_path)
|
||||||
|
@ -488,11 +520,23 @@ def make_parser(parser: argparse.ArgumentParser):
|
||||||
"needed if you want to build other packages that depend on this one."
|
"needed if you want to build other packages that depend on this one."
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--no-compress-package",
|
||||||
|
action="store_false",
|
||||||
|
default=True,
|
||||||
|
dest="compress_package",
|
||||||
|
help="Do not compress built packages.",
|
||||||
|
)
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
|
|
||||||
def main(args):
|
def main(args):
|
||||||
path = Path(args.package[0]).resolve()
|
path = Path(args.package[0]).resolve()
|
||||||
|
if args.compress_package and not _have_terser():
|
||||||
|
raise RuntimeError(
|
||||||
|
"Terser is required to compress packages. Try `npm install -g terser` to install terser."
|
||||||
|
)
|
||||||
|
|
||||||
build_package(path, args)
|
build_package(path, args)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue