@embroider/core 1.9.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/package.json +6 -20
  2. package/src/app.d.ts +4 -5
  3. package/src/app.js +48 -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 +7 -7
  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.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.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
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -51,7 +55,6 @@ const mergeWith_1 = __importDefault(require("lodash/mergeWith"));
51
55
  const cloneDeep_1 = __importDefault(require("lodash/cloneDeep"));
52
56
  const portable_1 = require("./portable");
53
57
  const escape_string_regexp_1 = __importDefault(require("escape-string-regexp"));
54
- const load_ember_template_compiler_1 = require("./load-ember-template-compiler");
55
58
  function excludeDotFiles(files) {
56
59
  return files.filter(file => !file.startsWith('.') && !file.includes('/.'));
57
60
  }
@@ -239,7 +242,7 @@ class AppBuilder {
239
242
  babel.plugins.push(require.resolve('@babel/plugin-syntax-dynamic-import'));
240
243
  return babel;
241
244
  }
242
- babelConfig(templateCompilerParams, appFiles) {
245
+ babelConfig(appFiles) {
243
246
  let babel = (0, cloneDeep_1.default)(this.adapter.babelConfig());
244
247
  if (!babel.plugins) {
245
248
  babel.plugins = [];
@@ -249,38 +252,38 @@ class AppBuilder {
249
252
  babel.plugins.push(require.resolve('@babel/plugin-syntax-dynamic-import'));
250
253
  // https://github.com/webpack/webpack/issues/12154
251
254
  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
- }
255
+ babel.plugins.push([require.resolve('babel-plugin-ember-template-compilation'), this.etcOptions()]);
279
256
  // this is @embroider/macros configured for full stage3 resolution
280
257
  babel.plugins.push(...this.macrosConfig.babelPluginConfig());
281
258
  let colocationOptions = {
282
- packageGuard: true,
283
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,
284
287
  };
285
288
  babel.plugins.push([
286
289
  require.resolve('@embroider/shared-internals/src/template-colocation-plugin'),
@@ -300,7 +303,7 @@ class AppBuilder {
300
303
  let relocatedFiles = {};
301
304
  for (let { destPath, appFiles } of engines) {
302
305
  for (let [relativePath, originalPath] of appFiles.relocatedFiles) {
303
- relocatedFiles[(0, path_1.join)(destPath, relativePath).split(path_1.sep).join('/')] = originalPath;
306
+ relocatedFiles[(0, path_1.join)(destPath, relativePath)] = originalPath;
304
307
  }
305
308
  }
306
309
  let relocatedFilesPath = (0, path_1.join)(this.root, '_relocated_files.json');
@@ -685,8 +688,7 @@ class AppBuilder {
685
688
  let emberENV = this.adapter.emberENV();
686
689
  let assets = this.gatherAssets(inputPaths);
687
690
  let finalAssets = await this.updateAssets(assets, appFiles, emberENV);
688
- let templateCompiler = this.templateCompiler(emberENV);
689
- let babelConfig = this.babelConfig(templateCompiler, appFiles);
691
+ let babelConfig = this.babelConfig(appFiles);
690
692
  this.addBabelConfig(babelConfig);
691
693
  let assetPaths = assets.map(asset => asset.relativePath);
692
694
  if (this.activeFastboot) {
@@ -731,24 +733,21 @@ class AppBuilder {
731
733
  pkgLayers.push({ keywords: ['ember-addon'], 'ember-addon': meta });
732
734
  return combinePackageJSON(...pkgLayers);
733
735
  }
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();
736
+ etcOptions() {
737
+ let transforms = this.adapter.htmlbarsPlugins();
738
+ let { plugins: macroPlugins, setConfig } = node_1.MacrosConfig.transforms();
740
739
  setConfig(this.macrosConfig);
741
740
  for (let macroPlugin of macroPlugins) {
742
- plugins.ast.push(macroPlugin);
741
+ transforms.push(macroPlugin);
742
+ }
743
+ let transform = this.adapter.resolverTransform();
744
+ if (transform) {
745
+ transforms.push(transform);
743
746
  }
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
747
  return {
747
- plugins,
748
- compilerPath,
749
- compilerChecksum,
750
- resolver: this.adapter.templateResolver(),
751
- 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'],
752
751
  };
753
752
  }
754
753
  get portableHints() {
@@ -847,11 +846,7 @@ class AppBuilder {
847
846
  }
848
847
  get staticAppPathsPattern() {
849
848
  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
- ')');
849
+ return new RegExp('^(?:' + this.options.staticAppPaths.map(staticAppPath => (0, escape_string_regexp_1.default)(staticAppPath)).join('|') + ')(?:$|/)');
855
850
  }
856
851
  }
857
852
  requiredOtherFiles(appFiles) {