@embroider/core 1.9.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. package/package.json +6 -20
  2. package/src/app.d.ts +4 -5
  3. package/src/app.js +43 -52
  4. package/src/app.js.map +1 -1
  5. package/src/babel-plugin-adjust-imports.d.ts +0 -1
  6. package/src/babel-plugin-adjust-imports.js +10 -17
  7. package/src/babel-plugin-adjust-imports.js.map +1 -1
  8. package/src/index.d.ts +0 -4
  9. package/src/index.js +2 -6
  10. package/src/index.js.map +1 -1
  11. package/src/messages.d.ts +3 -1
  12. package/src/messages.js +15 -4
  13. package/src/messages.js.map +1 -1
  14. package/src/packager.d.ts +4 -1
  15. package/src/packager.js +2 -1
  16. package/src/packager.js.map +1 -1
  17. package/src/portable-babel-config.js +1 -1
  18. package/src/portable-babel-config.js.map +1 -1
  19. package/src/babel-plugin-inline-hbs-deps-node.d.ts +0 -14
  20. package/src/babel-plugin-inline-hbs-deps-node.js +0 -27
  21. package/src/babel-plugin-inline-hbs-deps-node.js.map +0 -1
  22. package/src/babel-plugin-inline-hbs-deps.d.ts +0 -10
  23. package/src/babel-plugin-inline-hbs-deps.js +0 -134
  24. package/src/babel-plugin-inline-hbs-deps.js.map +0 -1
  25. package/src/babel-plugin-inline-hbs-node.d.ts +0 -7
  26. package/src/babel-plugin-inline-hbs-node.js +0 -15
  27. package/src/babel-plugin-inline-hbs-node.js.map +0 -1
  28. package/src/babel-plugin-inline-hbs.d.ts +0 -24
  29. package/src/babel-plugin-inline-hbs.js +0 -142
  30. package/src/babel-plugin-inline-hbs.js.map +0 -1
  31. package/src/babel-plugin-stage1-inline-hbs-node.d.ts +0 -12
  32. package/src/babel-plugin-stage1-inline-hbs-node.js +0 -9
  33. package/src/babel-plugin-stage1-inline-hbs-node.js.map +0 -1
  34. package/src/babel-plugin-stage1-inline-hbs.d.ts +0 -9
  35. package/src/babel-plugin-stage1-inline-hbs.js +0 -96
  36. package/src/babel-plugin-stage1-inline-hbs.js.map +0 -1
  37. package/src/browser-index.d.ts +0 -1
  38. package/src/browser-index.js +0 -6
  39. package/src/browser-index.js.map +0 -1
  40. package/src/ember-template-compiler-types.d.ts +0 -41
  41. package/src/ember-template-compiler-types.js +0 -3
  42. package/src/ember-template-compiler-types.js.map +0 -1
  43. package/src/load-ember-template-compiler.d.ts +0 -6
  44. package/src/load-ember-template-compiler.js +0 -57
  45. package/src/load-ember-template-compiler.js.map +0 -1
  46. package/src/mini-modules-polyfill.d.ts +0 -12
  47. package/src/mini-modules-polyfill.js +0 -80
  48. package/src/mini-modules-polyfill.js.map +0 -1
  49. package/src/patch-template-compiler.d.ts +0 -1
  50. package/src/patch-template-compiler.js +0 -176
  51. package/src/patch-template-compiler.js.map +0 -1
  52. package/src/resolver.d.ts +0 -14
  53. package/src/resolver.js +0 -3
  54. package/src/resolver.js.map +0 -1
  55. package/src/template-compiler-common.d.ts +0 -70
  56. package/src/template-compiler-common.js +0 -176
  57. package/src/template-compiler-common.js.map +0 -1
  58. package/src/template-compiler-node.d.ts +0 -17
  59. package/src/template-compiler-node.js +0 -32
  60. package/src/template-compiler-node.js.map +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@embroider/core",
3
- "version": "1.9.0",
3
+ "version": "2.0.1",
4
4
  "private": false,
5
5
  "description": "A build system for EmberJS applications.",
6
6
  "repository": {
@@ -11,24 +11,12 @@
11
11
  "license": "MIT",
12
12
  "author": "Edward Faulkner",
13
13
  "main": "src/index.js",
14
- "exports": {
15
- ".": {
16
- "browser": "./src/browser-index.js",
17
- "default": "./src/index.js"
18
- },
19
- "./src/messages": "./src/messages.js",
20
- "./src/babel-plugin-inline-hbs": "./src/babel-plugin-inline-hbs.js",
21
- "./src/babel-plugin-stage1-inline-hbs": "./src/babel-plugin-stage1-inline-hbs.js",
22
- "./src/mini-modules-polyfill": "./src/mini-modules-polyfill.js",
23
- "./src/load-ember-template-compiler": "./src/load-ember-template-compiler.js"
24
- },
25
14
  "files": [
26
15
  "src/**/*.js",
27
16
  "src/**/*.d.ts",
28
17
  "src/**/*.js.map"
29
18
  ],
30
19
  "scripts": {
31
- "prepare": "tsc",
32
20
  "test": "jest"
33
21
  },
34
22
  "dependencies": {
@@ -38,11 +26,11 @@
38
26
  "@babel/plugin-transform-runtime": "^7.14.5",
39
27
  "@babel/runtime": "^7.14.5",
40
28
  "@babel/traverse": "^7.14.5",
41
- "@embroider/macros": "1.9.0",
42
- "@embroider/shared-internals": "1.8.3",
29
+ "@embroider/macros": "1.10.0",
30
+ "@embroider/shared-internals": "2.0.0",
43
31
  "assert-never": "^1.2.1",
44
32
  "babel-import-util": "^1.1.0",
45
- "babel-plugin-ember-template-compilation": "^1.0.0",
33
+ "babel-plugin-ember-template-compilation": "^2.0.0",
46
34
  "broccoli-node-api": "^1.7.0",
47
35
  "broccoli-persistent-filter": "^3.1.2",
48
36
  "broccoli-plugin": "^4.0.7",
@@ -59,14 +47,13 @@
59
47
  "lodash": "^4.17.21",
60
48
  "resolve": "^1.20.0",
61
49
  "resolve-package-path": "^4.0.1",
62
- "strip-bom": "^4.0.0",
63
50
  "typescript-memoize": "^1.0.1",
64
- "walk-sync": "^3.0.0",
65
- "wrap-legacy-hbs-plugin-if-needed": "^1.0.1"
51
+ "walk-sync": "^3.0.0"
66
52
  },
67
53
  "devDependencies": {
68
54
  "@embroider/sample-transforms": "0.0.0",
69
55
  "@embroider/test-support": "0.36.0",
56
+ "@glimmer/syntax": "^0.84.2",
70
57
  "@types/babel__core": "^7.1.14",
71
58
  "@types/debug": "^4.1.5",
72
59
  "@types/filesize": "^4.0.0",
@@ -74,7 +61,6 @@
74
61
  "@types/lodash": "^4.14.170",
75
62
  "@types/node": "^15.12.2",
76
63
  "@types/resolve": "^1.20.0",
77
- "@types/strip-bom": "^4.0.1",
78
64
  "@types/tmp": "^0.1.0",
79
65
  "fixturify": "^2.1.1",
80
66
  "tmp": "^0.1.0",
package/src/app.d.ts CHANGED
@@ -4,9 +4,8 @@ import { Asset } from './asset';
4
4
  import Options from './options';
5
5
  import { MacrosConfig } from '@embroider/macros/src/node';
6
6
  import { TransformOptions } from '@babel/core';
7
- import { TemplateCompilerPlugins } from '.';
8
- import { Resolver } from './resolver';
9
7
  import { Options as AdjustImportsOptions } from './babel-plugin-adjust-imports';
8
+ import type { Transform } from 'babel-plugin-ember-template-compilation';
10
9
  export declare type EmberENV = unknown;
11
10
  export interface AppAdapter<TreeNames> {
12
11
  readonly allActiveAddons: AddonPackage[];
@@ -22,10 +21,10 @@ export interface AppAdapter<TreeNames> {
22
21
  podModulePrefix(): string | undefined;
23
22
  rootURL(): string;
24
23
  templateCompilerPath(): string;
25
- templateResolver(): Resolver;
24
+ resolverTransform(): Transform | undefined;
26
25
  adjustImportsOptions(): AdjustImportsOptions;
27
26
  adjustImportsOptionsPath(): string;
28
- htmlbarsPlugins(): TemplateCompilerPlugins;
27
+ htmlbarsPlugins(): Transform[];
29
28
  babelConfig(): TransformOptions;
30
29
  babelMajorVersion(): 7;
31
30
  emberENV(): EmberENV;
@@ -76,7 +75,7 @@ export declare class AppBuilder<TreeNames> {
76
75
  private gatherAssets;
77
76
  build(inputPaths: OutputPaths<TreeNames>): Promise<void>;
78
77
  private combinePackageJSON;
79
- private templateCompiler;
78
+ private etcOptions;
80
79
  private get portableHints();
81
80
  private addBabelConfig;
82
81
  private shouldSplitRoute;
package/src/app.js CHANGED
@@ -51,7 +51,6 @@ const mergeWith_1 = __importDefault(require("lodash/mergeWith"));
51
51
  const cloneDeep_1 = __importDefault(require("lodash/cloneDeep"));
52
52
  const portable_1 = require("./portable");
53
53
  const escape_string_regexp_1 = __importDefault(require("escape-string-regexp"));
54
- const load_ember_template_compiler_1 = require("./load-ember-template-compiler");
55
54
  function excludeDotFiles(files) {
56
55
  return files.filter(file => !file.startsWith('.') && !file.includes('/.'));
57
56
  }
@@ -239,7 +238,7 @@ class AppBuilder {
239
238
  babel.plugins.push(require.resolve('@babel/plugin-syntax-dynamic-import'));
240
239
  return babel;
241
240
  }
242
- babelConfig(templateCompilerParams, appFiles) {
241
+ babelConfig(appFiles) {
243
242
  let babel = (0, cloneDeep_1.default)(this.adapter.babelConfig());
244
243
  if (!babel.plugins) {
245
244
  babel.plugins = [];
@@ -249,38 +248,38 @@ class AppBuilder {
249
248
  babel.plugins.push(require.resolve('@babel/plugin-syntax-dynamic-import'));
250
249
  // https://github.com/webpack/webpack/issues/12154
251
250
  babel.plugins.push(require.resolve('./rename-require-plugin'));
252
- if (this.adapter.adjustImportsOptions().emberNeedsModulesPolyfill) {
253
- // on older ember versions that need the modules-api-polyfill, we use our
254
- // bespoke inline template compiler plugin.
255
- babel.plugins.push([
256
- (0, path_1.join)(__dirname, 'babel-plugin-inline-hbs-node.js'),
257
- {
258
- templateCompiler: templateCompilerParams,
259
- stage: 3,
260
- },
261
- ]);
262
- }
263
- else {
264
- // on newer ember versions that don't need the modules-api-polyfill, we
265
- // can compose with the newer babel-plugin-ember-template-compilation, and
266
- // use a simpler plugin that only needs to handle inserting discovered
267
- // dependencies.
268
- babel.plugins.push([
269
- (0, path_1.join)(__dirname, '../src/babel-plugin-inline-hbs-deps-node.js'),
270
- { templateCompiler: templateCompilerParams },
271
- ]);
272
- babel.plugins.push([
273
- require.resolve('babel-plugin-ember-template-compilation'),
274
- {
275
- precompilerPath: (0, path_1.join)(__dirname, '../src/babel-plugin-inline-hbs-deps-node.js'),
276
- },
277
- ]);
278
- }
251
+ babel.plugins.push([require.resolve('babel-plugin-ember-template-compilation'), this.etcOptions()]);
279
252
  // this is @embroider/macros configured for full stage3 resolution
280
253
  babel.plugins.push(...this.macrosConfig.babelPluginConfig());
281
254
  let colocationOptions = {
282
- packageGuard: true,
283
255
  appRoot: this.root,
256
+ // This extra weirdness is a compromise in favor of build performance.
257
+ //
258
+ // 1. When auto-upgrading an addon from v1 to v2, we definitely want to
259
+ // run any custom AST transforms in stage1.
260
+ //
261
+ // 2. In general case, AST transforms are allowed to manipulate Javascript
262
+ // scope. This means that running transforms -- even when we're doing
263
+ // source-to-source compilation that emits handlebars and not wire
264
+ // format -- implies changing .hbs files into .js files.
265
+ //
266
+ // 3. So stage1 may need to rewrite .hbs to .hbs.js (to avoid colliding
267
+ // with an existing co-located .js file).
268
+ //
269
+ // 4. But stage1 doesn't necessarily want to run babel over the
270
+ // corresponding JS file. Most of the time, that's just an
271
+ // unnecessarily expensive second parse. (We only run it in stage1 to
272
+ // eliminate an addon's custom babel plugins, and many addons don't
273
+ // have any.)
274
+ //
275
+ // 5. Therefore, the work of template-colocation gets defered until here,
276
+ // and it may see co-located templates named `.hbs.js` instead of the
277
+ // usual `.hbs.
278
+ templateExtensions: ['.hbs', '.hbs.js'],
279
+ // All of the above only applies to auto-upgraded packages that were
280
+ // authored in v1. V2 packages don't get any of this complexity, they're
281
+ // supposed to take care of colocating their own templates explicitly.
282
+ packageGuard: true,
284
283
  };
285
284
  babel.plugins.push([
286
285
  require.resolve('@embroider/shared-internals/src/template-colocation-plugin'),
@@ -300,7 +299,7 @@ class AppBuilder {
300
299
  let relocatedFiles = {};
301
300
  for (let { destPath, appFiles } of engines) {
302
301
  for (let [relativePath, originalPath] of appFiles.relocatedFiles) {
303
- relocatedFiles[(0, path_1.join)(destPath, relativePath).split(path_1.sep).join('/')] = originalPath;
302
+ relocatedFiles[(0, path_1.join)(destPath, relativePath)] = originalPath;
304
303
  }
305
304
  }
306
305
  let relocatedFilesPath = (0, path_1.join)(this.root, '_relocated_files.json');
@@ -685,8 +684,7 @@ class AppBuilder {
685
684
  let emberENV = this.adapter.emberENV();
686
685
  let assets = this.gatherAssets(inputPaths);
687
686
  let finalAssets = await this.updateAssets(assets, appFiles, emberENV);
688
- let templateCompiler = this.templateCompiler(emberENV);
689
- let babelConfig = this.babelConfig(templateCompiler, appFiles);
687
+ let babelConfig = this.babelConfig(appFiles);
690
688
  this.addBabelConfig(babelConfig);
691
689
  let assetPaths = assets.map(asset => asset.relativePath);
692
690
  if (this.activeFastboot) {
@@ -731,24 +729,21 @@ class AppBuilder {
731
729
  pkgLayers.push({ keywords: ['ember-addon'], 'ember-addon': meta });
732
730
  return combinePackageJSON(...pkgLayers);
733
731
  }
734
- templateCompiler(config) {
735
- let plugins = this.adapter.htmlbarsPlugins();
736
- if (!plugins.ast) {
737
- plugins.ast = [];
738
- }
739
- let { plugins: macroPlugins, setConfig } = node_1.MacrosConfig.astPlugins();
732
+ etcOptions() {
733
+ let transforms = this.adapter.htmlbarsPlugins();
734
+ let { plugins: macroPlugins, setConfig } = node_1.MacrosConfig.transforms();
740
735
  setConfig(this.macrosConfig);
741
736
  for (let macroPlugin of macroPlugins) {
742
- plugins.ast.push(macroPlugin);
737
+ transforms.push(macroPlugin);
738
+ }
739
+ let transform = this.adapter.resolverTransform();
740
+ if (transform) {
741
+ transforms.push(transform);
743
742
  }
744
- const compilerPath = resolve_1.default.sync(this.adapter.templateCompilerPath(), { basedir: this.root });
745
- const compilerChecksum = (0, load_ember_template_compiler_1.getEmberExports)(compilerPath).cacheKey;
746
743
  return {
747
- plugins,
748
- compilerPath,
749
- compilerChecksum,
750
- resolver: this.adapter.templateResolver(),
751
- EmberENV: config,
744
+ transforms,
745
+ compilerPath: resolve_1.default.sync(this.adapter.templateCompilerPath(), { basedir: this.root }),
746
+ enableLegacyModules: ['ember-cli-htmlbars', 'ember-cli-htmlbars-inline-precompile', 'htmlbars-inline-precompile'],
752
747
  };
753
748
  }
754
749
  get portableHints() {
@@ -847,11 +842,7 @@ class AppBuilder {
847
842
  }
848
843
  get staticAppPathsPattern() {
849
844
  if (this.options.staticAppPaths.length > 0) {
850
- return new RegExp('^(?:' +
851
- this.options.staticAppPaths.map(staticAppPath => (0, escape_string_regexp_1.default)(staticAppPath.replace(/\//g, path_1.sep))).join('|') +
852
- ')(?:$|' +
853
- path_1.sep +
854
- ')');
845
+ return new RegExp('^(?:' + this.options.staticAppPaths.map(staticAppPath => (0, escape_string_regexp_1.default)(staticAppPath)).join('|') + ')(?:$|/)');
855
846
  }
856
847
  }
857
848
  requiredOtherFiles(appFiles) {