From f6cba3605dd86c95b487e1948627e5f9be3a2e46 Mon Sep 17 00:00:00 2001 From: Chad Killingsworth Date: Wed, 16 May 2018 17:20:19 -0700 Subject: [PATCH] Rename code splitting flags from "module" to "chunk". Use aliases to be backwards compatible. Closes https://github.com/google/closure-compiler/pull/2925 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=196915847 --- .../javascript/jscomp/CommandLineRunner.java | 72 ++++++++++--------- .../jscomp/CommandLineRunnerTest.java | 22 +++--- 2 files changed, 49 insertions(+), 45 deletions(-) diff --git a/src/com/google/javascript/jscomp/CommandLineRunner.java b/src/com/google/javascript/jscomp/CommandLineRunner.java index 9a2f2b315cb..47ea4bde268 100644 --- a/src/com/google/javascript/jscomp/CommandLineRunner.java +++ b/src/com/google/javascript/jscomp/CommandLineRunner.java @@ -127,8 +127,8 @@ public class CommandLineRunner extends // UTF-8 BOM is 0xEF, 0xBB, 0xBF, of which character code is 65279. public static final int UTF8_BOM_CODE = 65279; - // Allowable module name characters that aren't valid in a JS identifier - private static final Pattern extraModuleNameChars = Pattern.compile("[-.]+"); + // Allowable chunk name characters that aren't valid in a JS identifier + private static final Pattern extraChunkNameChars = Pattern.compile("[-.]+"); // I don't really care about unchecked warnings in this class. @SuppressWarnings("unchecked") @@ -222,18 +222,19 @@ private static class Flags { + "written to stdout") private String jsOutputFile = ""; - @Option(name = "--module", - usage = "A JavaScript module specification. The format is " - + ":[:[,...][:]]]. Module names must be " - + "unique. Each dep is the name of a module that this module " - + "depends on. Modules must be listed in dependency order, and JS " + @Option(name = "--chunk", + usage = "A JavaScript chunk specification. The format is " + + ":[:[,...][:]]]. Chunk names must be " + + "unique. Each dep is the name of a chunk that this chunk " + + "depends on. Chunks must be listed in dependency order, and JS " + "source files must be listed in the corresponding order. Where " - + "--module flags occur in relation to --js flags is unimportant. " - + " may be set to 'auto' for the first module if it " + + "--chunk flags occur in relation to --js flags is unimportant. " + + " may be set to 'auto' for the first chunk if it " + "has no dependencies. " - + "Provide the value 'auto' to trigger module creation from CommonJS" - + "modules.") - private List module = new ArrayList<>(); + + "Provide the value 'auto' to trigger chunk creation from CommonJS" + + "modules.", + aliases = "--module") + private List chunk = new ArrayList<>(); @Option(name = "--continue-saved-compilation", usage = "Filename where the intermediate compilation state was previously saved.", @@ -310,22 +311,24 @@ private static class Flags { + " like newline in the wrapper.") private String outputWrapperFile = ""; - @Option(name = "--module_wrapper", - usage = "An output wrapper for a JavaScript module (optional). " - + "The format is :. The module name must correspond " - + "with a module specified using --module. The wrapper must " + @Option(name = "--chunk_wrapper", + usage = "An output wrapper for a JavaScript chunk (optional). " + + "The format is :. The chunk name must correspond " + + "with a chunk specified using --chunk. The wrapper must " + "contain %s as the code placeholder. " + "Alternately, %output% can be used in place of %s. " + "%n% can be used to represent a newline. " + "The %basename% placeholder can " - + "also be used to substitute the base name of the module output file.") - private List moduleWrapper = new ArrayList<>(); + + "also be used to substitute the base name of the chunk output file.", + aliases = "--module_wrapper") + private List chunkWrapper = new ArrayList<>(); - @Option(name = "--module_output_path_prefix", - usage = "Prefix for filenames of compiled JS modules. " - + ".js will be appended to this prefix. Directories " - + "will be created as needed. Use with --module") - private String moduleOutputPathPrefix = "./"; + @Option(name = "--chunk_output_path_prefix", + usage = "Prefix for filenames of compiled JS chunks. " + + ".js will be appended to this prefix. Directories " + + "will be created as needed. Use with --chunk", + aliases = "--module_output_path_prefix") + private String chunkOutputPathPrefix = "./"; @Option(name = "--create_source_map", usage = "If specified, a source map file mapping the generated " @@ -605,9 +608,10 @@ private static class Flags { ) private String outputManifest = ""; - @Option(name = "--output_module_dependencies", - usage = "Prints out a JSON file of dependencies between modules.") - private String outputModuleDependencies = ""; + @Option(name = "--output_chunk_dependencies", + usage = "Prints out a JSON file of dependencies between chunks.", + aliases = "--output_module_dependencies") + private String outputChunkDependencies = ""; @Option( name = "--language_in", @@ -889,13 +893,13 @@ private void parse(List args) throws CmdLineException { "rewrite_polyfills")) .putAll( "Code Splitting", - ImmutableList.of("module", "module_output_path_prefix", "module_wrapper")) + ImmutableList.of("chunk", "chunk_output_path_prefix", "chunk_wrapper")) .putAll( "Reports", ImmutableList.of( "create_source_map", "output_manifest", - "output_module_dependencies", + "output_chunk_dependencies", "property_renaming_report", "source_map_input", "source_map_include_content", @@ -1600,15 +1604,15 @@ private void initConfigFromFlags(String[] args, PrintStream out, PrintStream err .setJsOutputFile(flags.jsOutputFile) .setSaveAfterChecksFileName(flags.saveAfterChecksFile) .setContinueSavedCompilationFileName(flags.continueSavedCompilationFile) - .setModule(flags.module) + .setModule(flags.chunk) .setVariableMapOutputFile(flags.variableMapOutputFile) .setCreateNameMapFiles(flags.createNameMapFiles) .setPropertyMapOutputFile(flags.propertyMapOutputFile) .setCodingConvention(conv) .setSummaryDetailLevel(flags.summaryDetailLevel) .setOutputWrapper(flags.outputWrapper) - .setModuleWrapper(flags.moduleWrapper) - .setModuleOutputPathPrefix(flags.moduleOutputPathPrefix) + .setModuleWrapper(flags.chunkWrapper) + .setModuleOutputPathPrefix(flags.chunkOutputPathPrefix) .setCreateSourceMap(flags.createSourceMap) .setSourceMapFormat(flags.sourceMapFormat) .setSourceMapLocationMappings(mappings) @@ -1623,7 +1627,7 @@ private void initConfigFromFlags(String[] args, PrintStream out, PrintStream err .setOutputManifest(ImmutableList.of(flags.outputManifest)) .setOutputBundle(bundleFiles) .setSkipNormalOutputs(skipNormalOutputs) - .setOutputModuleDependencies(flags.outputModuleDependencies) + .setOutputModuleDependencies(flags.outputChunkDependencies) .setProcessCommonJSModules(flags.processCommonJsModules) .setModuleRoots(moduleRoots) .setTransformAMDToCJSModules(flags.transformAmdModules) @@ -1646,8 +1650,8 @@ protected void addWhitelistWarningsGuard( @Override protected void checkModuleName(String name) { if (!TokenStream.isJSIdentifier( - extraModuleNameChars.matcher(name).replaceAll("_"))) { - throw new FlagUsageException("Invalid module name: '" + name + "'"); + extraChunkNameChars.matcher(name).replaceAll("_"))) { + throw new FlagUsageException("Invalid chunk name: '" + name + "'"); } } diff --git a/test/com/google/javascript/jscomp/CommandLineRunnerTest.java b/test/com/google/javascript/jscomp/CommandLineRunnerTest.java index b547930aa86..1e79c709471 100644 --- a/test/com/google/javascript/jscomp/CommandLineRunnerTest.java +++ b/test/com/google/javascript/jscomp/CommandLineRunnerTest.java @@ -985,7 +985,7 @@ public void testSourceMapExpansion1() { public void testSourceMapExpansion2() { useModules = ModulePattern.CHAIN; args.add("--create_source_map=%outname%.map"); - args.add("--module_output_path_prefix=foo"); + args.add("--chunk_output_path_prefix=foo"); testSame(new String[] {"var x = 3;", "var y = 5;"}); assertThat(lastCommandLineRunner.expandSourceMapPath(lastCompiler.getOptions(), null)) .isEqualTo("foo.map"); @@ -994,7 +994,7 @@ public void testSourceMapExpansion2() { public void testSourceMapExpansion3() { useModules = ModulePattern.CHAIN; args.add("--create_source_map=%outname%.map"); - args.add("--module_output_path_prefix=foo_"); + args.add("--chunk_output_path_prefix=foo_"); testSame(new String[] {"var x = 3;", "var y = 5;"}); assertThat( lastCommandLineRunner.expandSourceMapPath( @@ -1005,7 +1005,7 @@ public void testSourceMapExpansion3() { public void testInvalidSourceMapPattern() { useModules = ModulePattern.CHAIN; args.add("--create_source_map=out.map"); - args.add("--module_output_path_prefix=foo_"); + args.add("--chunk_output_path_prefix=foo_"); test( new String[] {"var x = 3;", "var y = 5;"}, AbstractCommandLineRunner.INVALID_MODULE_SOURCEMAP_PATTERN); @@ -1284,7 +1284,7 @@ public void testSourceMapInputs() throws Exception { public void testModuleWrapperBaseNameExpansion() throws Exception { useModules = ModulePattern.CHAIN; - args.add("--module_wrapper=m0:%s // %basename%"); + args.add("--chunk_wrapper=m0:%s // %basename%"); testSame(new String[] { "var x = 3;", "var y = 4;" @@ -1299,7 +1299,7 @@ public void testModuleWrapperBaseNameExpansion() throws Exception { public void testModuleWrapperExpansion() throws Exception { useModules = ModulePattern.CHAIN; - args.add("--module_wrapper=m0:%output%%n%//# SourceMappingUrl=%basename%.map"); + args.add("--chunk_wrapper=m0:%output%%n%//# SourceMappingUrl=%basename%.map"); testSame(new String[] { "var x = 3;", "var y = 4;" @@ -1317,7 +1317,7 @@ public void testMultistageCompilation() throws Exception { String inputString = "[{\"src\": \"alert('foo');\", \"path\":\"foo.js\"}]"; args.add("--json_streams=BOTH"); - args.add("--module=foo--bar.baz:1"); + args.add("--chunk=foo--bar.baz:1"); // Perform stage1 List stage1Args = new ArrayList<>(args); @@ -1627,7 +1627,7 @@ public void testProcessCJS() { public void testProcessCJSWithModuleOutput() { args.add("--process_common_js_modules"); args.add("--entry_point=foo/bar"); - args.add("--module=auto"); + args.add("--chunk=auto"); setFilename(0, "foo/bar.js"); test("exports.test = 1", "var module$foo$bar={default: {}}; module$foo$bar.default.test = 1;"); // With modules=auto no direct output is created. @@ -1941,7 +1941,7 @@ public void testModuleJSON() { args.add("--transform_amd_modules"); args.add("--process_common_js_modules"); args.add("--entry_point=foo/bar"); - args.add("--output_module_dependencies=test.json"); + args.add("--output_chunk_dependencies=test.json"); setFilename(0, "foo/bar.js"); test( "define({foo: 1})", @@ -2096,7 +2096,7 @@ public void testJsonStreamSourceMap() { public void testOutputModuleNaming() { String inputString = "[{\"src\": \"alert('foo');\", \"path\":\"foo.js\"}]"; args.add("--json_streams=BOTH"); - args.add("--module=foo--bar.baz:1"); + args.add("--chunk=foo--bar.baz:1"); CommandLineRunner runner = new CommandLineRunner( @@ -2272,10 +2272,10 @@ private CommandLineRunner createCommandLineRunner(String[] original) { args.add("--js"); args.add("/path/to/input" + i + ".js"); if (useModules == ModulePattern.CHAIN) { - args.add("--module"); + args.add("--chunk"); args.add("m" + i + ":1" + (i > 0 ? (":m" + (i - 1)) : "")); } else if (useModules == ModulePattern.STAR) { - args.add("--module"); + args.add("--chunk"); args.add("m" + i + ":1" + (i > 0 ? ":m0" : "")); } }