@embroider/compat 3.1.5 → 3.1.6-unstable.1cdd50c

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.1.5",
3
+ "version": "3.1.6-unstable.1cdd50c",
4
4
  "private": false,
5
5
  "description": "Backward compatibility layer for the Embroider build system.",
6
6
  "repository": {
@@ -19,6 +19,9 @@
19
19
  "bin": {
20
20
  "embroider-compat-audit": "./src/audit-cli.js"
21
21
  },
22
+ "scripts": {
23
+ "test": "jest"
24
+ },
22
25
  "dependencies": {
23
26
  "@babel/code-frame": "^7.14.5",
24
27
  "@babel/core": "^7.14.5",
@@ -27,6 +30,7 @@
27
30
  "@babel/preset-env": "^7.14.5",
28
31
  "@babel/runtime": "^7.18.6",
29
32
  "@babel/traverse": "^7.14.5",
33
+ "@embroider/macros": "1.12.4-unstable.1cdd50c",
30
34
  "@types/babel__code-frame": "^7.0.2",
31
35
  "@types/yargs": "^17.0.3",
32
36
  "assert-never": "^1.1.0",
@@ -59,10 +63,12 @@
59
63
  "tree-sync": "^2.1.0",
60
64
  "typescript-memoize": "^1.0.1",
61
65
  "walk-sync": "^3.0.0",
62
- "yargs": "^17.0.1",
63
- "@embroider/macros": "1.12.3"
66
+ "yargs": "^17.0.1"
64
67
  },
65
68
  "devDependencies": {
69
+ "@embroider/core": "3.1.4-unstable.1cdd50c",
70
+ "@embroider/sample-transforms": "workspace:*",
71
+ "@embroider/test-support": "workspace:*",
66
72
  "@glimmer/syntax": "^0.84.2",
67
73
  "@glint/template": "^1.0.0",
68
74
  "@types/babel__core": "^7.1.14",
@@ -82,20 +88,15 @@
82
88
  "code-equality-assertions": "^0.9.0",
83
89
  "ember-engines": "^0.8.19",
84
90
  "scenario-tester": "^2.1.2",
85
- "typescript": "^5.1.6",
86
- "@embroider/sample-transforms": "0.0.0",
87
- "@embroider/test-support": "0.36.0"
91
+ "typescript": "^5.1.6"
88
92
  },
89
93
  "peerDependencies": {
90
- "@embroider/core": "^3.1.3"
94
+ "@embroider/core": "3.1.4-unstable.1cdd50c"
91
95
  },
92
96
  "engines": {
93
97
  "node": "12.* || 14.* || >= 16"
94
98
  },
95
99
  "volta": {
96
100
  "extends": "../../package.json"
97
- },
98
- "scripts": {
99
- "test": "jest"
100
101
  }
101
- }
102
+ }
@@ -1,4 +1,14 @@
1
1
  import V1Addon from '../v1-addon';
2
2
  export default class extends V1Addon {
3
3
  get v2Tree(): Node;
4
+ private get useStaticEmber();
5
+ private get includedDependencies();
6
+ get newPackageJSON(): import("@embroider/core").PackageInfo;
7
+ customizes(treeName: string): boolean;
8
+ invokeOriginalTreeFor(name: string, opts?: {
9
+ neuterPreprocessors: boolean;
10
+ }): any;
11
+ private customAddonTree;
12
+ private customVendorTree;
13
+ get packageMeta(): Partial<import("@embroider/core").AddonMeta>;
4
14
  }
@@ -1,4 +1,10 @@
1
1
  "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
2
8
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
9
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
10
  };
@@ -6,10 +12,161 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
12
  const v1_addon_1 = __importDefault(require("../v1-addon"));
7
13
  const broccoli_funnel_1 = __importDefault(require("broccoli-funnel"));
8
14
  const broccoli_merge_trees_1 = __importDefault(require("broccoli-merge-trees"));
15
+ const add_to_tree_1 = __importDefault(require("../add-to-tree"));
16
+ const fs_extra_1 = require("fs-extra");
17
+ const path_1 = require("path");
18
+ const typescript_memoize_1 = require("typescript-memoize");
19
+ const semver_1 = require("semver");
20
+ const core_1 = require("@babel/core");
21
+ const broccoli_plugin_1 = __importDefault(require("broccoli-plugin"));
9
22
  class default_1 extends v1_addon_1.default {
10
23
  get v2Tree() {
11
24
  return (0, broccoli_merge_trees_1.default)([super.v2Tree, (0, broccoli_funnel_1.default)(this.rootTree, { include: ['dist/ember-template-compiler.js'] })]);
12
25
  }
26
+ get useStaticEmber() {
27
+ return this.app.options.staticEmberSource;
28
+ }
29
+ // ember-source inlines a whole bunch of dependencies into itself
30
+ get includedDependencies() {
31
+ let result = [];
32
+ for (let name of (0, fs_extra_1.readdirSync)((0, path_1.resolve)(this.root, 'dist', 'dependencies'))) {
33
+ if (name[0] === '@') {
34
+ for (let innerName of (0, fs_extra_1.readdirSync)((0, path_1.resolve)(this.root, 'dist', 'dependencies', name))) {
35
+ if (innerName.endsWith('.js')) {
36
+ result.push(name + '/' + innerName.slice(0, -3));
37
+ }
38
+ }
39
+ }
40
+ else {
41
+ if (name.endsWith('.js')) {
42
+ result.push(name.slice(0, -3));
43
+ }
44
+ }
45
+ }
46
+ return result;
47
+ }
48
+ get newPackageJSON() {
49
+ var _a;
50
+ let json = super.newPackageJSON;
51
+ if (this.useStaticEmber) {
52
+ for (let name of this.includedDependencies) {
53
+ // weirdly, many of the inlined dependency are still listed as real
54
+ // dependencies too. If we don't delete them here, they will take
55
+ // precedence over the inlined ones, because the embroider module-resolver
56
+ // tries to prioritize real deps.
57
+ (_a = json.dependencies) === null || _a === void 0 ? true : delete _a[name];
58
+ }
59
+ }
60
+ return json;
61
+ }
62
+ customizes(treeName) {
63
+ if (this.useStaticEmber) {
64
+ // we are adding custom implementations of these
65
+ return treeName === 'treeForAddon' || treeName === 'treeForVendor' || super.customizes(treeName);
66
+ }
67
+ else {
68
+ return super.customizes(treeName);
69
+ }
70
+ }
71
+ invokeOriginalTreeFor(name, opts = { neuterPreprocessors: false }) {
72
+ if (this.useStaticEmber) {
73
+ if (name === 'addon') {
74
+ return this.customAddonTree();
75
+ }
76
+ if (name === 'vendor') {
77
+ return this.customVendorTree();
78
+ }
79
+ }
80
+ return super.invokeOriginalTreeFor(name, opts);
81
+ }
82
+ // Our addon tree is all of the "packages" we share. @embroider/compat already
83
+ // supports that pattern of emitting modules into other package's namespaces.
84
+ customAddonTree() {
85
+ let packages = (0, broccoli_funnel_1.default)(this.rootTree, {
86
+ srcDir: 'dist/packages',
87
+ });
88
+ let trees = [
89
+ packages,
90
+ (0, broccoli_funnel_1.default)(this.rootTree, {
91
+ srcDir: 'dist/dependencies',
92
+ }),
93
+ ];
94
+ if ((0, semver_1.satisfies)(this.packageJSON.version, '>= 4.0.0-alpha.0 <4.10.0-alpha.0', { includePrerelease: true })) {
95
+ // import { loc } from '@ember/string' was removed in 4.0. but the
96
+ // top-level `ember` package tries to import it until 4.10. A
97
+ // spec-compliant ES modules implementation will treat this as a parse
98
+ // error.
99
+ trees.push(new FixStringLoc([packages]));
100
+ }
101
+ return (0, broccoli_merge_trees_1.default)(trees, { overwrite: true });
102
+ }
103
+ // We're zeroing out these files in vendor rather than deleting them, because
104
+ // we can't easily intercept the `app.import` that presumably exists for them,
105
+ // so rather than error they will just be empty.
106
+ //
107
+ // The reason we're zeroing these out is that we're going to consume all our
108
+ // modules directly out of treeForAddon instead, as real modules that webpack
109
+ // can see.
110
+ customVendorTree() {
111
+ return new add_to_tree_1.default(this.addonInstance._treeFor('vendor'), outputPath => {
112
+ (0, fs_extra_1.unlinkSync)((0, path_1.join)(outputPath, 'ember', 'ember.js'));
113
+ (0, fs_extra_1.outputFileSync)((0, path_1.join)(outputPath, 'ember', 'ember.js'), '');
114
+ (0, fs_extra_1.unlinkSync)((0, path_1.join)(outputPath, 'ember', 'ember-testing.js'));
115
+ (0, fs_extra_1.outputFileSync)((0, path_1.join)(outputPath, 'ember', 'ember-testing.js'), '');
116
+ });
117
+ }
118
+ get packageMeta() {
119
+ let meta = super.packageMeta;
120
+ if (this.useStaticEmber) {
121
+ if (!meta['implicit-modules']) {
122
+ meta['implicit-modules'] = [];
123
+ }
124
+ meta['implicit-modules'].push('./ember/index.js');
125
+ if (!meta['implicit-test-modules']) {
126
+ meta['implicit-test-modules'] = [];
127
+ }
128
+ meta['implicit-test-modules'].push('./ember-testing/index.js');
129
+ }
130
+ return meta;
131
+ }
13
132
  }
14
133
  exports.default = default_1;
134
+ __decorate([
135
+ (0, typescript_memoize_1.Memoize)()
136
+ ], default_1.prototype, "includedDependencies", null);
137
+ class FixStringLoc extends broccoli_plugin_1.default {
138
+ build() {
139
+ let inSource = (0, fs_extra_1.readFileSync)((0, path_1.resolve)(this.inputPaths[0], 'ember', 'index.js'), 'utf8');
140
+ let outSource = (0, core_1.transform)(inSource, {
141
+ plugins: [fixStringLoc],
142
+ }).code;
143
+ (0, fs_extra_1.outputFileSync)((0, path_1.resolve)(this.outputPath, 'ember', 'index.js'), outSource, 'utf8');
144
+ }
145
+ }
146
+ function fixStringLoc(babel) {
147
+ let t = babel.types;
148
+ return {
149
+ visitor: {
150
+ Program(path) {
151
+ path.node.body.unshift(t.variableDeclaration('const', [t.variableDeclarator(t.identifier('loc'), t.identifier('undefined'))]));
152
+ },
153
+ ImportDeclaration: {
154
+ enter(path, state) {
155
+ if (path.node.source.value === '@ember/string') {
156
+ state.inEmberString = true;
157
+ }
158
+ },
159
+ exit(_path, state) {
160
+ state.inEmberString = false;
161
+ },
162
+ },
163
+ ImportSpecifier(path, state) {
164
+ let name = 'value' in path.node.imported ? path.node.imported.value : path.node.imported.name;
165
+ if (state.inEmberString && name === 'loc') {
166
+ path.remove();
167
+ }
168
+ },
169
+ },
170
+ };
171
+ }
15
172
  //# sourceMappingURL=ember-source.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ember-source.js","sourceRoot":"","sources":["ember-source.ts"],"names":[],"mappings":";;;;;AAAA,2DAAkC;AAClC,sEAA0C;AAC1C,gFAA8C;AAE9C,eAAqB,SAAQ,kBAAO;IAClC,IAAI,MAAM;QACR,OAAO,IAAA,8BAAU,EAAC,CAAC,KAAK,CAAC,MAAM,EAAE,IAAA,yBAAW,EAAC,IAAI,CAAC,QAAQ,EAAE,EAAE,OAAO,EAAE,CAAC,iCAAiC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAClH,CAAC;CACF;AAJD,4BAIC","sourcesContent":["import V1Addon from '../v1-addon';\nimport buildFunnel from 'broccoli-funnel';\nimport mergeTrees from 'broccoli-merge-trees';\n\nexport default class extends V1Addon {\n get v2Tree() {\n return mergeTrees([super.v2Tree, buildFunnel(this.rootTree, { include: ['dist/ember-template-compiler.js'] })]);\n }\n}\n"]}
1
+ {"version":3,"file":"ember-source.js","sourceRoot":"","sources":["ember-source.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,2DAAkC;AAClC,sEAA0C;AAC1C,gFAA8C;AAC9C,iEAAuC;AACvC,uCAAiF;AACjF,+BAAqC;AACrC,2DAA6C;AAC7C,mCAAmC;AACnC,sCAAwC;AAGxC,sEAAqC;AAGrC,eAAqB,SAAQ,kBAAO;IAClC,IAAI,MAAM;QACR,OAAO,IAAA,8BAAU,EAAC,CAAC,KAAK,CAAC,MAAM,EAAE,IAAA,yBAAW,EAAC,IAAI,CAAC,QAAQ,EAAE,EAAE,OAAO,EAAE,CAAC,iCAAiC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAClH,CAAC;IAED,IAAY,cAAc;QACxB,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,iBAAiB,CAAC;IAC5C,CAAC;IAED,iEAAiE;IAEjE,IAAY,oBAAoB;QAC9B,IAAI,MAAM,GAAa,EAAE,CAAC;QAC1B,KAAK,IAAI,IAAI,IAAI,IAAA,sBAAW,EAAC,IAAA,cAAO,EAAC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,cAAc,CAAC,CAAC,EAAE;YACxE,IAAI,IAA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,CAAC","sourcesContent":["import V1Addon from '../v1-addon';\nimport buildFunnel from 'broccoli-funnel';\nimport mergeTrees from 'broccoli-merge-trees';\nimport AddToTree from '../add-to-tree';\nimport { outputFileSync, readFileSync, readdirSync, unlinkSync } from 'fs-extra';\nimport { join, resolve } from 'path';\nimport { Memoize } from 'typescript-memoize';\nimport { satisfies } from 'semver';\nimport { transform } from '@babel/core';\nimport type * as Babel from '@babel/core';\nimport type { NodePath } from '@babel/traverse';\nimport Plugin from 'broccoli-plugin';\nimport { Node } from 'broccoli-node-api';\n\nexport default class extends V1Addon {\n get v2Tree() {\n return mergeTrees([super.v2Tree, buildFunnel(this.rootTree, { include: ['dist/ember-template-compiler.js'] })]);\n }\n\n private get useStaticEmber(): boolean {\n return this.app.options.staticEmberSource;\n }\n\n // ember-source inlines a whole bunch of dependencies into itself\n @Memoize()\n private get includedDependencies() {\n let result: string[] = [];\n for (let name of readdirSync(resolve(this.root, 'dist', 'dependencies'))) {\n if (name[0] === '@') {\n for (let innerName of readdirSync(resolve(this.root, 'dist', 'dependencies', name))) {\n if (innerName.endsWith('.js')) {\n result.push(name + '/' + innerName.slice(0, -3));\n }\n }\n } else {\n if (name.endsWith('.js')) {\n result.push(name.slice(0, -3));\n }\n }\n }\n return result;\n }\n\n get newPackageJSON() {\n let json = super.newPackageJSON;\n if (this.useStaticEmber) {\n for (let name of this.includedDependencies) {\n // weirdly, many of the inlined dependency are still listed as real\n // dependencies too. If we don't delete them here, they will take\n // precedence over the inlined ones, because the embroider module-resolver\n // tries to prioritize real deps.\n delete json.dependencies?.[name];\n }\n }\n return json;\n }\n\n customizes(treeName: string) {\n if (this.useStaticEmber) {\n // we are adding custom implementations of these\n return treeName === 'treeForAddon' || treeName === 'treeForVendor' || super.customizes(treeName);\n } else {\n return super.customizes(treeName);\n }\n }\n\n invokeOriginalTreeFor(name: string, opts: { neuterPreprocessors: boolean } = { neuterPreprocessors: false }) {\n if (this.useStaticEmber) {\n if (name === 'addon') {\n return this.customAddonTree();\n }\n if (name === 'vendor') {\n return this.customVendorTree();\n }\n }\n return super.invokeOriginalTreeFor(name, opts);\n }\n\n // Our addon tree is all of the \"packages\" we share. @embroider/compat already\n // supports that pattern of emitting modules into other package's namespaces.\n private customAddonTree() {\n let packages = buildFunnel(this.rootTree, {\n srcDir: 'dist/packages',\n });\n\n let trees: Node[] = [\n packages,\n buildFunnel(this.rootTree, {\n srcDir: 'dist/dependencies',\n }),\n ];\n\n if (satisfies(this.packageJSON.version, '>= 4.0.0-alpha.0 <4.10.0-alpha.0', { includePrerelease: true })) {\n // import { loc } from '@ember/string' was removed in 4.0. but the\n // top-level `ember` package tries to import it until 4.10. A\n // spec-compliant ES modules implementation will treat this as a parse\n // error.\n trees.push(new FixStringLoc([packages]));\n }\n\n return mergeTrees(trees, { overwrite: true });\n }\n\n // We're zeroing out these files in vendor rather than deleting them, because\n // we can't easily intercept the `app.import` that presumably exists for them,\n // so rather than error they will just be empty.\n //\n // The reason we're zeroing these out is that we're going to consume all our\n // modules directly out of treeForAddon instead, as real modules that webpack\n // can see.\n private customVendorTree() {\n return new AddToTree(this.addonInstance._treeFor('vendor'), outputPath => {\n unlinkSync(join(outputPath, 'ember', 'ember.js'));\n outputFileSync(join(outputPath, 'ember', 'ember.js'), '');\n unlinkSync(join(outputPath, 'ember', 'ember-testing.js'));\n outputFileSync(join(outputPath, 'ember', 'ember-testing.js'), '');\n });\n }\n\n get packageMeta() {\n let meta = super.packageMeta;\n if (this.useStaticEmber) {\n if (!meta['implicit-modules']) {\n meta['implicit-modules'] = [];\n }\n meta['implicit-modules'].push('./ember/index.js');\n\n if (!meta['implicit-test-modules']) {\n meta['implicit-test-modules'] = [];\n }\n meta['implicit-test-modules'].push('./ember-testing/index.js');\n }\n return meta;\n }\n}\n\nclass FixStringLoc extends Plugin {\n build() {\n let inSource = readFileSync(resolve(this.inputPaths[0], 'ember', 'index.js'), 'utf8');\n let outSource = transform(inSource, {\n plugins: [fixStringLoc],\n })!.code!;\n outputFileSync(resolve(this.outputPath, 'ember', 'index.js'), outSource, 'utf8');\n }\n}\n\nfunction fixStringLoc(babel: typeof Babel) {\n let t = babel.types;\n return {\n visitor: {\n Program(path: NodePath<Babel.types.Program>) {\n path.node.body.unshift(\n t.variableDeclaration('const', [t.variableDeclarator(t.identifier('loc'), t.identifier('undefined'))])\n );\n },\n ImportDeclaration: {\n enter(path: NodePath<Babel.types.ImportDeclaration>, state: { inEmberString: boolean }) {\n if (path.node.source.value === '@ember/string') {\n state.inEmberString = true;\n }\n },\n exit(_path: NodePath<Babel.types.ImportDeclaration>, state: { inEmberString: boolean }) {\n state.inEmberString = false;\n },\n },\n ImportSpecifier(path: NodePath<Babel.types.ImportSpecifier>, state: { inEmberString: boolean }) {\n let name = 'value' in path.node.imported ? path.node.imported.value : path.node.imported.name;\n if (state.inEmberString && name === 'loc') {\n path.remove();\n }\n },\n },\n };\n}\n"]}
package/src/options.d.ts CHANGED
@@ -5,6 +5,7 @@ import { PackageRules } from './dependency-rules';
5
5
  export default interface Options extends CoreOptions {
6
6
  staticAddonTrees?: boolean;
7
7
  staticAddonTestSupportTrees?: boolean;
8
+ staticEmberSource?: boolean;
8
9
  compatAdapters?: Map<string, V1AddonConstructor | null>;
9
10
  extraPublicTrees?: Node[];
10
11
  packageRules?: PackageRules[];
package/src/options.js CHANGED
@@ -5,6 +5,7 @@ const core_1 = require("@embroider/core");
5
5
  const defaults = Object.assign((0, core_1.optionsWithDefaults)(), {
6
6
  staticAddonTrees: false,
7
7
  staticAddonTestSupportTrees: false,
8
+ staticEmberSource: false,
8
9
  compatAdapters: new Map(),
9
10
  extraPublicTrees: [],
10
11
  workspaceDir: null,
@@ -27,6 +28,7 @@ exports.recommendedOptions = Object.freeze({
27
28
  staticHelpers: true,
28
29
  staticModifiers: true,
29
30
  staticComponents: true,
31
+ staticEmberSource: true,
30
32
  allowUnsafeDynamicComponents: false,
31
33
  }),
32
34
  });
@@ -1 +1 @@
1
- {"version":3,"file":"options.js","sourceRoot":"","sources":["options.ts"],"names":[],"mappings":";;;AAEA,0CAAkG;AAsFlG,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,IAAA,0BAAgB,GAAE,EAAE;IACjD,gBAAgB,EAAE,KAAK;IACvB,2BAA2B,EAAE,KAAK;IAClC,cAAc,EAAE,IAAI,GAAG,EAAE;IACzB,gBAAgB,EAAE,EAAE;IACpB,YAAY,EAAE,IAAI;IAClB,YAAY,EAAE,EAAE;IAChB,4BAA4B,EAAE,KAAK;CACpC,CAAC,CAAC;AAEH,SAAgB,mBAAmB,CAAC,OAAiB;IACnD,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;AAC9C,CAAC;AAFD,kDAEC;AAED,+EAA+E;AAC/E,6EAA6E;AAC7E,+EAA+E;AAC/E,cAAc;AACD,QAAA,kBAAkB,GAAgC,MAAM,CAAC,MAAM,CAAC;IAC3E,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC,MAAM,CAAC;QACvB,gBAAgB,EAAE,IAAI;QACtB,2BAA2B,EAAE,IAAI;QACjC,aAAa,EAAE,IAAI;QACnB,eAAe,EAAE,IAAI;QACrB,gBAAgB,EAAE,IAAI;QACtB,4BAA4B,EAAE,KAAK;KACpC,CAAC;CACH,CAAC,CAAC","sourcesContent":["import { V1AddonConstructor } from './v1-addon';\nimport { Node } from 'broccoli-node-api';\nimport { Options as CoreOptions, optionsWithDefaults as coreWithDefaults } from '@embroider/core';\nimport { PackageRules } from './dependency-rules';\n\n// These options control how hard we will try to achieve compatibility with v1\n// addons. The defaults are conservative and try to maximize compatibility, at\n// the cost of slower or bigger builds. As you eliminate sources of legacy\n// behavior you can benefit from the more aggressive modes.\nexport default interface Options extends CoreOptions {\n // Controls whether your addon's \"addon\" trees should be resolved statically\n // at build time.\n //\n // false (the default): implies maximum backward compatibility at the cost\n // of bigger builds. In this mode, we force every file into the Ember app,\n // which is the legacy behavior.\n //\n // true: produces smaller builds. The addon files must be imported from\n // somewhere we can statically see during the build. In this mode, your app\n // will only include files that are actually imported from somewhere.\n //\n // Commentary: most v1 addons already work well with this set to true, because\n // they tend to either offer Javascript that users are supposed to directly\n // `import` or components / helpers / services that get directly imported and\n // re-exported by code in App Javascript. The exceptions are addons that do\n // runtime shenanigans with `require` or scoped runtime resolutions.\n //\n // To workaround an addon that is preventing you from enabling this flag, you\n // can use addonDependencyRules.\n staticAddonTrees?: boolean;\n\n // Controls whether your addon's \"addonTestSupport\" trees should be resolved\n // statically at build time.\n //\n // false (the default): implies maximum backward compatibility at the cost\n // of bigger builds. All test support files will be forced into your Ember\n // app, which is the legacy behavior.\n //\n // true: produces smaller builds. Only files that are explicitly imported\n // will end up in your app.\n //\n // Commentary: this is analogous to staticAddonTrees and the same guidelines\n // apply.\n staticAddonTestSupportTrees?: boolean;\n\n // Allows you to override how specific addons will build. Like:\n //\n // import V1Addon from '@embroider/compat'; let compatAdapters = new Map();\n // compatAdapters.set('some-addon', class extends V1Addon {// do stuff here:\n // see examples in ./compat-adapters\n // });\n //\n // This should be understood as a temporary way to keep yourself from getting\n // stuck, not an alternative to actually fixing upstream. For the most part,\n // the real solution will be converting the addon in question to natively\n // publish as v2.\n //\n // We ship with some default compatAdapters to fix otherwise incompatible\n // behaviors in popular addons. You can override the default adapters by\n // setting your own value here (including null to completely disable it).\n compatAdapters?: Map<string, V1AddonConstructor | null>;\n\n // optional list of additional broccoli trees that should be incorporated into\n // the final build. This exists because the classic `app.toTree()` method\n // accepts an optional tree argument that has the same purpose.\n extraPublicTrees?: Node[];\n\n // Allows you to tell Embroider about otherwise dynamic dependencies within\n // your app and addons that it can't figure out on its own. These are combined\n // with the default rules that ship with Embroider. Your own rules take\n // precedence over the built-ins. Order matters, first matching rule will\n // apply to any given addon.\n //\n // See the addon-dependency-rules directory in the @embroider/compat package\n // for the built-in rules.\n //\n // These ONLY APPLY to v1-formatted addons. An addon that ships as native v2\n // is expected to do the right thing on its own.\n //\n // Follow to the definition of PackageRules for more info.\n packageRules?: PackageRules[];\n\n // This turns build errors into runtime errors. It is not a good idea to keep\n // it on in production. But it can be helpful when testing how much of your\n // app is able to work with staticComponents enabled.\n allowUnsafeDynamicComponents?: boolean;\n}\n\nconst defaults = Object.assign(coreWithDefaults(), {\n staticAddonTrees: false,\n staticAddonTestSupportTrees: false,\n compatAdapters: new Map(),\n extraPublicTrees: [],\n workspaceDir: null,\n packageRules: [],\n allowUnsafeDynamicComponents: false,\n});\n\nexport function optionsWithDefaults(options?: Options): Required<Options> {\n return Object.assign({}, defaults, options);\n}\n\n// These are recommended configurations for addons to test themselves under. By\n// keeping them here, it's easier to do ecosystem-wide compatibility testing.\n// See the `@embroider/test-setup` package which can help consume these to test\n// them in CI.\nexport const recommendedOptions: { [name: string]: Options } = Object.freeze({\n safe: Object.freeze({}),\n optimized: Object.freeze({\n staticAddonTrees: true,\n staticAddonTestSupportTrees: true,\n staticHelpers: true,\n staticModifiers: true,\n staticComponents: true,\n allowUnsafeDynamicComponents: false,\n }),\n});\n"]}
1
+ {"version":3,"file":"options.js","sourceRoot":"","sources":["options.ts"],"names":[],"mappings":";;;AAEA,0CAAkG;AAgGlG,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,IAAA,0BAAgB,GAAE,EAAE;IACjD,gBAAgB,EAAE,KAAK;IACvB,2BAA2B,EAAE,KAAK;IAClC,iBAAiB,EAAE,KAAK;IACxB,cAAc,EAAE,IAAI,GAAG,EAAE;IACzB,gBAAgB,EAAE,EAAE;IACpB,YAAY,EAAE,IAAI;IAClB,YAAY,EAAE,EAAE;IAChB,4BAA4B,EAAE,KAAK;CACpC,CAAC,CAAC;AAEH,SAAgB,mBAAmB,CAAC,OAAiB;IACnD,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;AAC9C,CAAC;AAFD,kDAEC;AAED,+EAA+E;AAC/E,6EAA6E;AAC7E,+EAA+E;AAC/E,cAAc;AACD,QAAA,kBAAkB,GAAgC,MAAM,CAAC,MAAM,CAAC;IAC3E,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC,MAAM,CAAC;QACvB,gBAAgB,EAAE,IAAI;QACtB,2BAA2B,EAAE,IAAI;QACjC,aAAa,EAAE,IAAI;QACnB,eAAe,EAAE,IAAI;QACrB,gBAAgB,EAAE,IAAI;QACtB,iBAAiB,EAAE,IAAI;QACvB,4BAA4B,EAAE,KAAK;KACpC,CAAC;CACH,CAAC,CAAC","sourcesContent":["import { V1AddonConstructor } from './v1-addon';\nimport { Node } from 'broccoli-node-api';\nimport { Options as CoreOptions, optionsWithDefaults as coreWithDefaults } from '@embroider/core';\nimport { PackageRules } from './dependency-rules';\n\n// These options control how hard we will try to achieve compatibility with v1\n// addons. The defaults are conservative and try to maximize compatibility, at\n// the cost of slower or bigger builds. As you eliminate sources of legacy\n// behavior you can benefit from the more aggressive modes.\nexport default interface Options extends CoreOptions {\n // Controls whether your addon's \"addon\" trees should be resolved statically\n // at build time.\n //\n // false (the default): implies maximum backward compatibility at the cost\n // of bigger builds. In this mode, we force every file into the Ember app,\n // which is the legacy behavior.\n //\n // true: produces smaller builds. The addon files must be imported from\n // somewhere we can statically see during the build. In this mode, your app\n // will only include files that are actually imported from somewhere.\n //\n // Commentary: most v1 addons already work well with this set to true, because\n // they tend to either offer Javascript that users are supposed to directly\n // `import` or components / helpers / services that get directly imported and\n // re-exported by code in App Javascript. The exceptions are addons that do\n // runtime shenanigans with `require` or scoped runtime resolutions.\n //\n // To workaround an addon that is preventing you from enabling this flag, you\n // can use addonDependencyRules.\n staticAddonTrees?: boolean;\n\n // Controls whether your addon's \"addonTestSupport\" trees should be resolved\n // statically at build time.\n //\n // false (the default): implies maximum backward compatibility at the cost\n // of bigger builds. All test support files will be forced into your Ember\n // app, which is the legacy behavior.\n //\n // true: produces smaller builds. Only files that are explicitly imported\n // will end up in your app.\n //\n // Commentary: this is analogous to staticAddonTrees and the same guidelines\n // apply.\n staticAddonTestSupportTrees?: boolean;\n\n // when true, we will load ember-source as ES modules. This means unused parts\n // of ember-source won't be included. But it also means that addons using old\n // APIs to try to `require()` things from Ember -- particularly from within\n // vendor.js -- cannot do that anymore.\n //\n // When false (the default) we load ember-source the traditional way, which is\n // that a big ol' script gets smooshed into vendor.js, and none of ember's\n // public module API actually exists as modules at build time.\n staticEmberSource?: boolean;\n\n // Allows you to override how specific addons will build. Like:\n //\n // import V1Addon from '@embroider/compat'; let compatAdapters = new Map();\n // compatAdapters.set('some-addon', class extends V1Addon {// do stuff here:\n // see examples in ./compat-adapters\n // });\n //\n // This should be understood as a temporary way to keep yourself from getting\n // stuck, not an alternative to actually fixing upstream. For the most part,\n // the real solution will be converting the addon in question to natively\n // publish as v2.\n //\n // We ship with some default compatAdapters to fix otherwise incompatible\n // behaviors in popular addons. You can override the default adapters by\n // setting your own value here (including null to completely disable it).\n compatAdapters?: Map<string, V1AddonConstructor | null>;\n\n // optional list of additional broccoli trees that should be incorporated into\n // the final build. This exists because the classic `app.toTree()` method\n // accepts an optional tree argument that has the same purpose.\n extraPublicTrees?: Node[];\n\n // Allows you to tell Embroider about otherwise dynamic dependencies within\n // your app and addons that it can't figure out on its own. These are combined\n // with the default rules that ship with Embroider. Your own rules take\n // precedence over the built-ins. Order matters, first matching rule will\n // apply to any given addon.\n //\n // See the addon-dependency-rules directory in the @embroider/compat package\n // for the built-in rules.\n //\n // These ONLY APPLY to v1-formatted addons. An addon that ships as native v2\n // is expected to do the right thing on its own.\n //\n // Follow to the definition of PackageRules for more info.\n packageRules?: PackageRules[];\n\n // This turns build errors into runtime errors. It is not a good idea to keep\n // it on in production. But it can be helpful when testing how much of your\n // app is able to work with staticComponents enabled.\n allowUnsafeDynamicComponents?: boolean;\n}\n\nconst defaults = Object.assign(coreWithDefaults(), {\n staticAddonTrees: false,\n staticAddonTestSupportTrees: false,\n staticEmberSource: false,\n compatAdapters: new Map(),\n extraPublicTrees: [],\n workspaceDir: null,\n packageRules: [],\n allowUnsafeDynamicComponents: false,\n});\n\nexport function optionsWithDefaults(options?: Options): Required<Options> {\n return Object.assign({}, defaults, options);\n}\n\n// These are recommended configurations for addons to test themselves under. By\n// keeping them here, it's easier to do ecosystem-wide compatibility testing.\n// See the `@embroider/test-setup` package which can help consume these to test\n// them in CI.\nexport const recommendedOptions: { [name: string]: Options } = Object.freeze({\n safe: Object.freeze({}),\n optimized: Object.freeze({\n staticAddonTrees: true,\n staticAddonTestSupportTrees: true,\n staticHelpers: true,\n staticModifiers: true,\n staticComponents: true,\n staticEmberSource: true,\n allowUnsafeDynamicComponents: false,\n }),\n});\n"]}
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2018 Edward Faulkner
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.