@embroider/compat 3.5.7-unstable.d9fc688 → 3.5.7-unstable.dce753f

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@embroider/compat",
3
- "version": "3.5.7-unstable.d9fc688",
3
+ "version": "3.5.7-unstable.dce753f",
4
4
  "private": false,
5
5
  "description": "Backward compatibility layer for the Embroider build system.",
6
6
  "repository": {
@@ -45,7 +45,6 @@
45
45
  "broccoli-source": "^3.0.1",
46
46
  "chalk": "^4.1.1",
47
47
  "debug": "^4.3.2",
48
- "escape-string-regexp": "^4.0.0",
49
48
  "fast-sourcemap-concat": "^2.1.1",
50
49
  "fs-extra": "^9.1.0",
51
50
  "fs-tree-diff": "^2.0.1",
@@ -53,6 +52,7 @@
53
52
  "lodash": "^4.17.21",
54
53
  "pkg-up": "^3.1.0",
55
54
  "resolve": "^1.20.0",
55
+ "resolve.exports": "^2.0.2",
56
56
  "resolve-package-path": "^4.0.1",
57
57
  "semver": "^7.3.5",
58
58
  "symlink-or-copy": "^1.3.1",
@@ -60,7 +60,7 @@
60
60
  "typescript-memoize": "^1.0.1",
61
61
  "walk-sync": "^3.0.0",
62
62
  "yargs": "^17.0.1",
63
- "@embroider/macros": "1.16.6-unstable.d9fc688"
63
+ "@embroider/macros": "1.16.6-unstable.dce753f"
64
64
  },
65
65
  "devDependencies": {
66
66
  "@glimmer/syntax": "^0.84.3",
@@ -83,12 +83,12 @@
83
83
  "ember-engines": "^0.8.19",
84
84
  "scenario-tester": "^3.0.1",
85
85
  "typescript": "^5.4.5",
86
- "@embroider/core": "^3.4.15-unstable.d9fc688",
86
+ "@embroider/sample-transforms": "0.0.0",
87
87
  "@embroider/test-support": "0.36.0",
88
- "@embroider/sample-transforms": "0.0.0"
88
+ "@embroider/core": "^3.4.15-unstable.dce753f"
89
89
  },
90
90
  "peerDependencies": {
91
- "@embroider/core": "^3.4.15-unstable.d9fc688"
91
+ "@embroider/core": "^3.4.15-unstable.dce753f"
92
92
  },
93
93
  "engines": {
94
94
  "node": "12.* || 14.* || >= 16"
@@ -1,12 +1,9 @@
1
- import type { Node as BroccoliNode } from 'broccoli-node-api';
2
- import type { OutputPaths } from '@embroider/core';
3
1
  import type Options from './options';
4
2
  import type ContentForConfig from './content-for-config';
5
3
  import type { V1Config } from './v1-config';
6
4
  import type { Package } from '@embroider/core';
7
5
  import type CompatApp from './compat-app';
8
6
  export declare class CompatAppBuilder {
9
- private root;
10
7
  private origAppPackage;
11
8
  private appPackageWithMovedDeps;
12
9
  private options;
@@ -15,32 +12,22 @@ export declare class CompatAppBuilder {
15
12
  private contentForTree;
16
13
  private synthVendor;
17
14
  private synthStyles;
18
- constructor(root: string, origAppPackage: Package, appPackageWithMovedDeps: Package, options: Required<Options>, compatApp: CompatApp, configTree: V1Config, contentForTree: ContentForConfig, synthVendor: Package, synthStyles: Package);
19
- private fastbootJSSrcDir;
15
+ constructor(origAppPackage: Package, appPackageWithMovedDeps: Package, options: Required<Options>, compatApp: CompatApp, configTree: V1Config, contentForTree: ContentForConfig, synthVendor: Package, synthStyles: Package);
20
16
  private activeAddonChildren;
21
17
  private get allActiveAddons();
22
18
  private isActiveAddon;
23
19
  private orderAddons;
24
20
  private resolvableExtensions;
25
- private addEmberEntrypoints;
26
21
  private modulePrefix;
27
22
  private podModulePrefix;
28
- private rootURL;
29
23
  private activeRules;
30
24
  private resolverConfig;
31
- private get resolvableExtensionsPattern();
32
25
  private babelConfig;
33
26
  private findActiveAddons;
34
27
  private partitionEngines;
35
- private get activeFastboot();
36
28
  private emberVersion;
37
- private get fastbootConfig();
38
29
  private engines;
39
- private updateAppJS;
40
- private get staticAppPathsPattern();
41
- private firstBuild;
42
- build(inputPaths: OutputPaths<TreeNames>): Promise<void>;
43
- private combinePackageJSON;
30
+ build(): Promise<void>;
44
31
  private etcOptions;
45
32
  private get portableHints();
46
33
  private addBabelConfig;
@@ -50,10 +37,3 @@ export declare class CompatAppBuilder {
50
37
  private addMacrosConfig;
51
38
  private outputAppBootError;
52
39
  }
53
- interface TreeNames {
54
- appJS: BroccoliNode;
55
- htmlTree: BroccoliNode;
56
- publicTree: BroccoliNode | undefined;
57
- configTree: BroccoliNode;
58
- }
59
- export {};
@@ -14,25 +14,20 @@ const core_1 = require("@embroider/core");
14
14
  const path_1 = require("path");
15
15
  const dependency_rules_1 = require("./dependency-rules");
16
16
  const flatMap_1 = __importDefault(require("lodash/flatMap"));
17
- const mergeWith_1 = __importDefault(require("lodash/mergeWith"));
18
17
  const cloneDeep_1 = __importDefault(require("lodash/cloneDeep"));
19
18
  const bind_decorator_1 = __importDefault(require("bind-decorator"));
20
19
  const fs_extra_1 = require("fs-extra");
21
20
  const portable_babel_config_1 = require("@embroider/core/src/portable-babel-config");
22
- const app_files_1 = require("@embroider/core/src/app-files");
23
21
  const portable_1 = require("@embroider/core/src/portable");
24
22
  const typescript_memoize_1 = require("typescript-memoize");
25
23
  const path_2 = require("path");
26
24
  const resolve_1 = __importDefault(require("resolve"));
27
25
  const fs_extra_2 = require("fs-extra");
28
26
  const node_1 = require("@embroider/macros/src/node");
29
- const escape_string_regexp_1 = __importDefault(require("escape-string-regexp"));
30
- const sync_dir_1 = require("./sync-dir");
31
27
  // This exists during the actual broccoli build step. As opposed to CompatApp,
32
28
  // which also exists during pipeline-construction time.
33
29
  class CompatAppBuilder {
34
- constructor(root, origAppPackage, appPackageWithMovedDeps, options, compatApp, configTree, contentForTree, synthVendor, synthStyles) {
35
- this.root = root;
30
+ constructor(origAppPackage, appPackageWithMovedDeps, options, compatApp, configTree, contentForTree, synthVendor, synthStyles) {
36
31
  this.origAppPackage = origAppPackage;
37
32
  this.appPackageWithMovedDeps = appPackageWithMovedDeps;
38
33
  this.options = options;
@@ -41,13 +36,6 @@ class CompatAppBuilder {
41
36
  this.contentForTree = contentForTree;
42
37
  this.synthVendor = synthVendor;
43
38
  this.synthStyles = synthStyles;
44
- this.firstBuild = true;
45
- }
46
- fastbootJSSrcDir() {
47
- let target = (0, path_2.join)(this.compatApp.root, 'fastboot');
48
- if ((0, fs_extra_2.pathExistsSync)(target)) {
49
- return target;
50
- }
51
39
  }
52
40
  activeAddonChildren(pkg) {
53
41
  let result = pkg.dependencies.filter(this.isActiveAddon).filter(
@@ -99,30 +87,15 @@ class CompatAppBuilder {
99
87
  // ember-cli-typescript
100
88
  return ['.wasm', '.mjs', '.js', '.json', '.ts', '.hbs', '.hbs.js', '.gjs', '.gts'];
101
89
  }
102
- addEmberEntrypoints(htmlTreePath) {
103
- let classicEntrypoints = ['index.html', 'tests/index.html'];
104
- if (!this.compatApp.shouldBuildTests) {
105
- classicEntrypoints.pop();
106
- }
107
- for (let entrypoint of classicEntrypoints) {
108
- let sourcePath = (0, path_2.join)(htmlTreePath, entrypoint);
109
- let rewrittenAppPath = (0, path_2.join)(this.root, entrypoint);
110
- (0, fs_extra_1.writeFileSync)(rewrittenAppPath, (0, fs_extra_1.readFileSync)(sourcePath));
111
- }
112
- return classicEntrypoints;
113
- }
114
90
  modulePrefix() {
115
91
  return this.configTree.readConfig().modulePrefix;
116
92
  }
117
93
  podModulePrefix() {
118
94
  return this.configTree.readConfig().podModulePrefix;
119
95
  }
120
- rootURL() {
121
- return this.configTree.readConfig().rootURL;
122
- }
123
96
  activeRules() {
124
97
  return (0, dependency_rules_1.activePackageRules)(this.options.packageRules.concat(defaultAddonPackageRules()), [
125
- { name: this.origAppPackage.name, version: this.origAppPackage.version, root: this.root },
98
+ { name: this.origAppPackage.name, version: this.origAppPackage.version, root: this.origAppPackage.root },
126
99
  ...this.allActiveAddons.filter(p => p.meta['auto-upgraded']),
127
100
  ]);
128
101
  }
@@ -141,13 +114,12 @@ class CompatAppBuilder {
141
114
  renamePackages,
142
115
  resolvableExtensions: this.resolvableExtensions(),
143
116
  appRoot: this.origAppPackage.root,
144
- engines: engines.map((appFiles, index) => ({
145
- packageName: appFiles.engine.package.name,
146
- // first engine is the app, which has been relocated to this.root
117
+ engines: engines.map(engine => ({
118
+ packageName: engine.package.name,
147
119
  // we need to use the real path here because webpack requests always use the real path i.e. follow symlinks
148
- root: (0, fs_extra_1.realpathSync)(index === 0 ? this.root : appFiles.engine.package.root),
149
- fastbootFiles: appFiles.fastbootFiles,
150
- activeAddons: [...appFiles.engine.addons]
120
+ root: (0, fs_extra_1.realpathSync)(engine.package.root),
121
+ fastbootFiles: {},
122
+ activeAddons: [...engine.addons]
151
123
  .map(([addon, canResolveFromFile]) => ({
152
124
  name: addon.name,
153
125
  root: addon.root,
@@ -157,7 +129,7 @@ class CompatAppBuilder {
157
129
  // that the last one wins. Our resolver's order is the order to
158
130
  // search, so first one wins.
159
131
  .reverse(),
160
- isLazy: appFiles.engine.package.isLazyEngine(),
132
+ isLazy: engine.package.isLazyEngine(),
161
133
  })),
162
134
  amdCompatibility: this.options.amdCompatibility,
163
135
  // this is the additional stufff that @embroider/compat adds on top to do
@@ -172,9 +144,6 @@ class CompatAppBuilder {
172
144
  };
173
145
  return config;
174
146
  }
175
- get resolvableExtensionsPattern() {
176
- return (0, core_1.extensionsPattern)(this.resolvableExtensions());
177
- }
178
147
  async babelConfig(resolverConfig) {
179
148
  let babel = (0, cloneDeep_1.default)(this.compatApp.babelConfig());
180
149
  if (!babel.plugins) {
@@ -236,7 +205,7 @@ class CompatAppBuilder {
236
205
  require.resolve('@babel/plugin-transform-runtime'),
237
206
  { absoluteRuntime: __dirname, useESModules: true, regenerator: false },
238
207
  ]);
239
- const portable = (0, portable_babel_config_1.makePortable)(babel, { basedir: this.root }, this.portableHints);
208
+ const portable = (0, portable_babel_config_1.makePortable)(babel, { basedir: this.origAppPackage.root }, this.portableHints);
240
209
  addCachablePlugin(portable.config);
241
210
  return portable;
242
211
  }
@@ -249,16 +218,7 @@ class CompatAppBuilder {
249
218
  if (!child.isEngine()) {
250
219
  this.findActiveAddons(child, engine, true);
251
220
  }
252
- let canResolveFrom;
253
- if (pkg === this.appPackageWithMovedDeps) {
254
- // we want canResolveFrom to always be a rewritten package path, and our
255
- // app's package is not rewritten yet here.
256
- canResolveFrom = (0, path_1.resolve)(this.root, 'package.json');
257
- }
258
- else {
259
- // whereas our addons are already moved
260
- canResolveFrom = (0, path_1.resolve)(pkg.root, 'package.json');
261
- }
221
+ let canResolveFrom = (0, path_1.resolve)(pkg.root, 'package.json');
262
222
  engine.addons.set(child, canResolveFrom);
263
223
  }
264
224
  // ensure addons are applied in the correct order, if set (via @embroider/compat/v1-addon)
@@ -294,7 +254,7 @@ class CompatAppBuilder {
294
254
  addons: new Map(),
295
255
  isApp: !current,
296
256
  modulePrefix: addon.name,
297
- appRelativePath: (0, core_1.explicitRelative)(this.root, addon.root),
257
+ appRelativePath: (0, core_1.explicitRelative)(this.origAppPackage.root, addon.root),
298
258
  });
299
259
  }
300
260
  }
@@ -302,9 +262,6 @@ class CompatAppBuilder {
302
262
  }
303
263
  return done;
304
264
  }
305
- get activeFastboot() {
306
- return this.activeAddonChildren(this.appPackageWithMovedDeps).find(a => a.name === 'ember-cli-fastboot');
307
- }
308
265
  emberVersion() {
309
266
  let pkg = this.activeAddonChildren(this.appPackageWithMovedDeps).find(a => a.name === 'ember-source');
310
267
  if (!pkg) {
@@ -312,82 +269,14 @@ class CompatAppBuilder {
312
269
  }
313
270
  return pkg.version;
314
271
  }
315
- get fastbootConfig() {
316
- if (this.activeFastboot) {
317
- // this is relying on work done in stage1 by @embroider/compat/src/compat-adapters/ember-cli-fastboot.ts
318
- let packageJSON = (0, fs_extra_1.readJSONSync)((0, path_2.join)(this.activeFastboot.root, '_fastboot_', 'package.json'));
319
- let { extraAppFiles, extraVendorFiles } = packageJSON['embroider-fastboot'];
320
- delete packageJSON['embroider-fastboot'];
321
- extraVendorFiles.push('assets/embroider_macros_fastboot_init.js');
322
- return { packageJSON, extraAppFiles, extraVendorFiles };
323
- }
324
- }
325
- updateAppJS(appJSPath) {
326
- var _a;
327
- if (!this.engines) {
328
- this.engines = this.partitionEngines().map(engine => {
329
- if (engine.isApp) {
330
- // this is the app. We have more to do for the app than for other
331
- // engines.
332
- let fastbootSync;
333
- if (this.activeFastboot) {
334
- let fastbootDir = this.fastbootJSSrcDir();
335
- if (fastbootDir) {
336
- fastbootSync = new sync_dir_1.SyncDir(fastbootDir, (0, path_1.resolve)(this.root, '_fastboot_'));
337
- }
338
- }
339
- return {
340
- engine,
341
- appSync: new sync_dir_1.SyncDir(appJSPath, this.root),
342
- fastbootSync,
343
- };
344
- }
345
- else {
346
- // this is not the app, so it's some other engine. Engines are already
347
- // built by stage1 like all other addons, so we only need to observe
348
- // their files, not doing any actual copying or building.
349
- return {
350
- engine,
351
- appSync: new sync_dir_1.SyncDir(engine.package.root, undefined),
352
- // AFAIK, we've never supported a fastboot overlay directory in an
353
- // engine. But if we do need that, it would go here.
354
- fastbootSync: undefined,
355
- };
356
- }
357
- });
358
- }
359
- for (let engine of this.engines) {
360
- engine.appSync.update();
361
- (_a = engine.fastbootSync) === null || _a === void 0 ? void 0 : _a.update();
362
- }
363
- return this.engines.map(({ engine, appSync, fastbootSync }) => {
364
- var _a;
365
- return new app_files_1.AppFiles(engine, appSync.files, (_a = fastbootSync === null || fastbootSync === void 0 ? void 0 : fastbootSync.files) !== null && _a !== void 0 ? _a : new Set(), this.resolvableExtensionsPattern, this.staticAppPathsPattern, this.podModulePrefix());
366
- });
367
- }
368
- get staticAppPathsPattern() {
369
- if (this.options.staticAppPaths.length > 0) {
370
- return new RegExp('^(?:' + this.options.staticAppPaths.map(staticAppPath => (0, escape_string_regexp_1.default)(staticAppPath)).join('|') + ')(?:$|/)');
371
- }
372
- }
373
- async build(inputPaths) {
272
+ async build() {
374
273
  // on the first build, we lock down the macros config. on subsequent builds,
375
274
  // this doesn't do anything anyway because it's idempotent.
376
275
  this.compatApp.macrosConfig.finalize();
377
- // on first build, clear the output directory completely
378
- if (this.firstBuild) {
379
- (0, fs_extra_1.rmSync)(this.root, { recursive: true, force: true });
380
- this.firstBuild = false;
381
- }
382
- let appFiles = this.updateAppJS(inputPaths.appJS);
383
- let assetPaths = this.addEmberEntrypoints(inputPaths.htmlTree);
384
- if (this.activeFastboot) {
385
- // when using fastboot, our own package.json needs to be in the output so fastboot can read it.
386
- assetPaths.push('package.json');
276
+ if (!this.engines) {
277
+ this.engines = this.partitionEngines();
387
278
  }
388
- let pkg = this.combinePackageJSON(assetPaths);
389
- (0, fs_extra_1.writeFileSync)((0, path_2.join)(this.root, 'package.json'), JSON.stringify(pkg, null, 2), 'utf8');
390
- let resolverConfig = this.resolverConfig(appFiles);
279
+ let resolverConfig = this.resolverConfig(this.engines);
391
280
  let config = this.configTree.readConfig();
392
281
  let contentForConfig = this.contentForTree.readContents();
393
282
  this.addResolverConfig(resolverConfig);
@@ -398,32 +287,6 @@ class CompatAppBuilder {
398
287
  this.addBabelConfig(babelConfig);
399
288
  this.addMacrosConfig(this.compatApp.macrosConfig.babelPluginConfig()[0]);
400
289
  }
401
- combinePackageJSON(assetPaths) {
402
- var _a, _b;
403
- let pkgLayers = [this.origAppPackage.packageJSON];
404
- let fastbootConfig = this.fastbootConfig;
405
- if (fastbootConfig) {
406
- // fastboot-specific package.json output is allowed to add to our original package.json
407
- pkgLayers.push(fastbootConfig.packageJSON);
408
- }
409
- let meta = {
410
- type: 'app',
411
- version: 2,
412
- assets: assetPaths,
413
- babel: {
414
- filename: '_babel_config_.js',
415
- isParallelSafe: true, // TODO
416
- majorVersion: this.compatApp.babelMajorVersion(),
417
- fileFilter: '_babel_filter_.js',
418
- },
419
- 'root-url': this.rootURL(),
420
- };
421
- if (((_b = (_a = this.origAppPackage.packageJSON['ember-addon']) === null || _a === void 0 ? void 0 : _a.version) !== null && _b !== void 0 ? _b : 0) < 2) {
422
- meta['auto-upgraded'] = true;
423
- }
424
- pkgLayers.push({ 'ember-addon': meta });
425
- return combinePackageJSON(...pkgLayers);
426
- }
427
290
  async etcOptions(resolverConfig) {
428
291
  let transforms = this.compatApp.htmlbarsPlugins;
429
292
  let { plugins: macroPlugins, setConfig } = node_1.MacrosConfig.transforms();
@@ -442,9 +305,9 @@ class CompatAppBuilder {
442
305
  transforms.push([require.resolve('./resolver-transform'), opts]);
443
306
  }
444
307
  let resolver = new core_1.Resolver(resolverConfig);
445
- let resolution = await resolver.nodeResolve('ember-source/vendor/ember/ember-template-compiler', (0, path_1.resolve)(this.root, 'package.json'));
308
+ let resolution = await resolver.nodeResolve('ember-source/vendor/ember/ember-template-compiler', (0, path_1.resolve)(this.origAppPackage.root, 'package.json'));
446
309
  if (resolution.type !== 'real') {
447
- throw new Error(`bug: unable to resolve ember-template-compiler from ${this.root}`);
310
+ throw new Error(`bug: unable to resolve ember-template-compiler from ${this.origAppPackage.root}`);
448
311
  }
449
312
  return {
450
313
  transforms,
@@ -548,9 +411,6 @@ class CompatAppBuilder {
548
411
  }
549
412
  }
550
413
  exports.CompatAppBuilder = CompatAppBuilder;
551
- __decorate([
552
- (0, typescript_memoize_1.Memoize)()
553
- ], CompatAppBuilder.prototype, "fastbootJSSrcDir", null);
554
414
  __decorate([
555
415
  (0, typescript_memoize_1.Memoize)()
556
416
  ], CompatAppBuilder.prototype, "allActiveAddons", null);
@@ -563,21 +423,9 @@ __decorate([
563
423
  __decorate([
564
424
  (0, typescript_memoize_1.Memoize)()
565
425
  ], CompatAppBuilder.prototype, "activeRules", null);
566
- __decorate([
567
- (0, typescript_memoize_1.Memoize)()
568
- ], CompatAppBuilder.prototype, "resolvableExtensionsPattern", null);
569
426
  __decorate([
570
427
  (0, typescript_memoize_1.Memoize)()
571
428
  ], CompatAppBuilder.prototype, "babelConfig", null);
572
- __decorate([
573
- (0, typescript_memoize_1.Memoize)()
574
- ], CompatAppBuilder.prototype, "activeFastboot", null);
575
- __decorate([
576
- (0, typescript_memoize_1.Memoize)()
577
- ], CompatAppBuilder.prototype, "fastbootConfig", null);
578
- __decorate([
579
- (0, typescript_memoize_1.Memoize)()
580
- ], CompatAppBuilder.prototype, "staticAppPathsPattern", null);
581
429
  __decorate([
582
430
  (0, typescript_memoize_1.Memoize)()
583
431
  ], CompatAppBuilder.prototype, "portableHints", null);
@@ -596,16 +444,6 @@ const babelFilterTemplate = (0, core_1.jsHandlebarsCompile)(`
596
444
  const { babelFilter } = require(${JSON.stringify(require.resolve('@embroider/core'))});
597
445
  module.exports = babelFilter({{json-stringify skipBabel}}, "{{js-string-escape appRoot}}");
598
446
  `);
599
- function combinePackageJSON(...layers) {
600
- function custom(objValue, srcValue, key, _object, _source, stack) {
601
- if (key === 'keywords' && stack.size === 0) {
602
- if (Array.isArray(objValue)) {
603
- return objValue.concat(srcValue);
604
- }
605
- }
606
- }
607
- return (0, mergeWith_1.default)({}, ...layers, custom);
608
- }
609
447
  function addCachablePlugin(babelConfig) {
610
448
  if (Array.isArray(babelConfig.plugins) && babelConfig.plugins.length > 0) {
611
449
  const plugins = Object.create(null);