@embroider/core 1.8.3 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. package/package.json +6 -20
  2. package/src/app.d.ts +4 -5
  3. package/src/app.js +44 -53
  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/atomic-write.d.ts +0 -1
  20. package/src/atomic-write.js +0 -18
  21. package/src/atomic-write.js.map +0 -1
  22. package/src/babel-plugin-inline-hbs-deps-node.d.ts +0 -14
  23. package/src/babel-plugin-inline-hbs-deps-node.js +0 -31
  24. package/src/babel-plugin-inline-hbs-deps-node.js.map +0 -1
  25. package/src/babel-plugin-inline-hbs-deps.d.ts +0 -10
  26. package/src/babel-plugin-inline-hbs-deps.js +0 -134
  27. package/src/babel-plugin-inline-hbs-deps.js.map +0 -1
  28. package/src/babel-plugin-inline-hbs-node.d.ts +0 -7
  29. package/src/babel-plugin-inline-hbs-node.js +0 -15
  30. package/src/babel-plugin-inline-hbs-node.js.map +0 -1
  31. package/src/babel-plugin-inline-hbs.d.ts +0 -24
  32. package/src/babel-plugin-inline-hbs.js +0 -142
  33. package/src/babel-plugin-inline-hbs.js.map +0 -1
  34. package/src/babel-plugin-stage1-inline-hbs-node.d.ts +0 -12
  35. package/src/babel-plugin-stage1-inline-hbs-node.js +0 -9
  36. package/src/babel-plugin-stage1-inline-hbs-node.js.map +0 -1
  37. package/src/babel-plugin-stage1-inline-hbs.d.ts +0 -9
  38. package/src/babel-plugin-stage1-inline-hbs.js +0 -96
  39. package/src/babel-plugin-stage1-inline-hbs.js.map +0 -1
  40. package/src/browser-index.d.ts +0 -1
  41. package/src/browser-index.js +0 -6
  42. package/src/browser-index.js.map +0 -1
  43. package/src/ember-template-compiler-types.d.ts +0 -41
  44. package/src/ember-template-compiler-types.js +0 -3
  45. package/src/ember-template-compiler-types.js.map +0 -1
  46. package/src/load-ember-template-compiler.d.ts +0 -6
  47. package/src/load-ember-template-compiler.js +0 -57
  48. package/src/load-ember-template-compiler.js.map +0 -1
  49. package/src/mini-modules-polyfill.d.ts +0 -12
  50. package/src/mini-modules-polyfill.js +0 -80
  51. package/src/mini-modules-polyfill.js.map +0 -1
  52. package/src/patch-template-compiler.d.ts +0 -1
  53. package/src/patch-template-compiler.js +0 -176
  54. package/src/patch-template-compiler.js.map +0 -1
  55. package/src/resolver.d.ts +0 -14
  56. package/src/resolver.js +0 -3
  57. package/src/resolver.js.map +0 -1
  58. package/src/template-compiler-common.d.ts +0 -70
  59. package/src/template-compiler-common.js +0 -176
  60. package/src/template-compiler-common.js.map +0 -1
  61. package/src/template-compiler-node.d.ts +0 -17
  62. package/src/template-compiler-node.js +0 -32
  63. package/src/template-compiler-node.js.map +0 -1
  64. package/src/write-template-compiler.d.ts +0 -6
  65. package/src/write-template-compiler.js +0 -24
  66. package/src/write-template-compiler.js.map +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@embroider/core",
3
- "version": "1.8.3",
3
+ "version": "2.0.0",
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.8.3",
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
@@ -55,7 +55,6 @@ const mergeWith_1 = __importDefault(require("lodash/mergeWith"));
55
55
  const cloneDeep_1 = __importDefault(require("lodash/cloneDeep"));
56
56
  const portable_1 = require("./portable");
57
57
  const escape_string_regexp_1 = __importDefault(require("escape-string-regexp"));
58
- const load_ember_template_compiler_1 = require("./load-ember-template-compiler");
59
58
  function excludeDotFiles(files) {
60
59
  return files.filter(file => !file.startsWith('.') && !file.includes('/.'));
61
60
  }
@@ -172,7 +171,7 @@ class AppBuilder {
172
171
  result.unshift({
173
172
  kind: 'in-memory',
174
173
  relativePath: '_ember_env_.js',
175
- source: `window.EmberENV=${JSON.stringify(emberENV, null, 2)};`,
174
+ source: `window.EmberENV={ ...(window.EmberENV || {}), ...${JSON.stringify(emberENV, null, 2)} };`,
176
175
  });
177
176
  result.push({
178
177
  kind: 'in-memory',
@@ -243,7 +242,7 @@ class AppBuilder {
243
242
  babel.plugins.push(require.resolve('@babel/plugin-syntax-dynamic-import'));
244
243
  return babel;
245
244
  }
246
- babelConfig(templateCompilerParams, appFiles) {
245
+ babelConfig(appFiles) {
247
246
  let babel = (0, cloneDeep_1.default)(this.adapter.babelConfig());
248
247
  if (!babel.plugins) {
249
248
  babel.plugins = [];
@@ -253,38 +252,38 @@ class AppBuilder {
253
252
  babel.plugins.push(require.resolve('@babel/plugin-syntax-dynamic-import'));
254
253
  // https://github.com/webpack/webpack/issues/12154
255
254
  babel.plugins.push(require.resolve('./rename-require-plugin'));
256
- if (this.adapter.adjustImportsOptions().emberNeedsModulesPolyfill) {
257
- // on older ember versions that need the modules-api-polyfill, we use our
258
- // bespoke inline template compiler plugin.
259
- babel.plugins.push([
260
- (0, path_1.join)(__dirname, 'babel-plugin-inline-hbs-node.js'),
261
- {
262
- templateCompiler: templateCompilerParams,
263
- stage: 3,
264
- },
265
- ]);
266
- }
267
- else {
268
- // on newer ember versions that don't need the modules-api-polyfill, we
269
- // can compose with the newer babel-plugin-ember-template-compilation, and
270
- // use a simpler plugin that only needs to handle inserting discovered
271
- // dependencies.
272
- babel.plugins.push([
273
- (0, path_1.join)(__dirname, '../src/babel-plugin-inline-hbs-deps-node.js'),
274
- { templateCompiler: templateCompilerParams },
275
- ]);
276
- babel.plugins.push([
277
- require.resolve('babel-plugin-ember-template-compilation'),
278
- {
279
- precompilerPath: (0, path_1.join)(__dirname, '../src/babel-plugin-inline-hbs-deps-node.js'),
280
- },
281
- ]);
282
- }
255
+ babel.plugins.push([require.resolve('babel-plugin-ember-template-compilation'), this.etcOptions()]);
283
256
  // this is @embroider/macros configured for full stage3 resolution
284
257
  babel.plugins.push(...this.macrosConfig.babelPluginConfig());
285
258
  let colocationOptions = {
286
- packageGuard: true,
287
259
  appRoot: this.root,
260
+ // This extra weirdness is a compromise in favor of build performance.
261
+ //
262
+ // 1. When auto-upgrading an addon from v1 to v2, we definitely want to
263
+ // run any custom AST transforms in stage1.
264
+ //
265
+ // 2. In general case, AST transforms are allowed to manipulate Javascript
266
+ // scope. This means that running transforms -- even when we're doing
267
+ // source-to-source compilation that emits handlebars and not wire
268
+ // format -- implies changing .hbs files into .js files.
269
+ //
270
+ // 3. So stage1 may need to rewrite .hbs to .hbs.js (to avoid colliding
271
+ // with an existing co-located .js file).
272
+ //
273
+ // 4. But stage1 doesn't necessarily want to run babel over the
274
+ // corresponding JS file. Most of the time, that's just an
275
+ // unnecessarily expensive second parse. (We only run it in stage1 to
276
+ // eliminate an addon's custom babel plugins, and many addons don't
277
+ // have any.)
278
+ //
279
+ // 5. Therefore, the work of template-colocation gets defered until here,
280
+ // and it may see co-located templates named `.hbs.js` instead of the
281
+ // usual `.hbs.
282
+ templateExtensions: ['.hbs', '.hbs.js'],
283
+ // All of the above only applies to auto-upgraded packages that were
284
+ // authored in v1. V2 packages don't get any of this complexity, they're
285
+ // supposed to take care of colocating their own templates explicitly.
286
+ packageGuard: true,
288
287
  };
289
288
  babel.plugins.push([
290
289
  require.resolve('@embroider/shared-internals/src/template-colocation-plugin'),
@@ -304,7 +303,7 @@ class AppBuilder {
304
303
  let relocatedFiles = {};
305
304
  for (let { destPath, appFiles } of engines) {
306
305
  for (let [relativePath, originalPath] of appFiles.relocatedFiles) {
307
- relocatedFiles[(0, path_1.join)(destPath, relativePath).split(path_1.sep).join('/')] = originalPath;
306
+ relocatedFiles[(0, path_1.join)(destPath, relativePath)] = originalPath;
308
307
  }
309
308
  }
310
309
  let relocatedFilesPath = (0, path_1.join)(this.root, '_relocated_files.json');
@@ -689,8 +688,7 @@ class AppBuilder {
689
688
  let emberENV = this.adapter.emberENV();
690
689
  let assets = this.gatherAssets(inputPaths);
691
690
  let finalAssets = await this.updateAssets(assets, appFiles, emberENV);
692
- let templateCompiler = this.templateCompiler(emberENV);
693
- let babelConfig = this.babelConfig(templateCompiler, appFiles);
691
+ let babelConfig = this.babelConfig(appFiles);
694
692
  this.addBabelConfig(babelConfig);
695
693
  let assetPaths = assets.map(asset => asset.relativePath);
696
694
  if (this.activeFastboot) {
@@ -735,24 +733,21 @@ class AppBuilder {
735
733
  pkgLayers.push({ keywords: ['ember-addon'], 'ember-addon': meta });
736
734
  return combinePackageJSON(...pkgLayers);
737
735
  }
738
- templateCompiler(config) {
739
- let plugins = this.adapter.htmlbarsPlugins();
740
- if (!plugins.ast) {
741
- plugins.ast = [];
742
- }
743
- let { plugins: macroPlugins, setConfig } = node_1.MacrosConfig.astPlugins();
736
+ etcOptions() {
737
+ let transforms = this.adapter.htmlbarsPlugins();
738
+ let { plugins: macroPlugins, setConfig } = node_1.MacrosConfig.transforms();
744
739
  setConfig(this.macrosConfig);
745
740
  for (let macroPlugin of macroPlugins) {
746
- plugins.ast.push(macroPlugin);
741
+ transforms.push(macroPlugin);
742
+ }
743
+ let transform = this.adapter.resolverTransform();
744
+ if (transform) {
745
+ transforms.push(transform);
747
746
  }
748
- const compilerPath = resolve_1.default.sync(this.adapter.templateCompilerPath(), { basedir: this.root });
749
- const compilerChecksum = (0, load_ember_template_compiler_1.getEmberExports)(compilerPath).cacheKey;
750
747
  return {
751
- plugins,
752
- compilerPath,
753
- compilerChecksum,
754
- resolver: this.adapter.templateResolver(),
755
- EmberENV: config,
748
+ transforms,
749
+ compilerPath: resolve_1.default.sync(this.adapter.templateCompilerPath(), { basedir: this.root }),
750
+ enableLegacyModules: ['ember-cli-htmlbars', 'ember-cli-htmlbars-inline-precompile', 'htmlbars-inline-precompile'],
756
751
  };
757
752
  }
758
753
  get portableHints() {
@@ -851,11 +846,7 @@ class AppBuilder {
851
846
  }
852
847
  get staticAppPathsPattern() {
853
848
  if (this.options.staticAppPaths.length > 0) {
854
- return new RegExp('^(?:' +
855
- this.options.staticAppPaths.map(staticAppPath => (0, escape_string_regexp_1.default)(staticAppPath.replace(/\//g, path_1.sep))).join('|') +
856
- ')(?:$|' +
857
- path_1.sep +
858
- ')');
849
+ return new RegExp('^(?:' + this.options.staticAppPaths.map(staticAppPath => (0, escape_string_regexp_1.default)(staticAppPath)).join('|') + ')(?:$|/)');
859
850
  }
860
851
  }
861
852
  requiredOtherFiles(appFiles) {