@embroider/compat 3.8.1 → 4.0.0-alpha.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.
- package/babel.js +1 -0
- package/package.json +21 -15
- package/src/audit/babel-visitor.js +7 -1
- package/src/audit/babel-visitor.js.map +1 -1
- package/src/audit/build.js.map +1 -1
- package/src/audit/options.d.ts +2 -1
- package/src/audit/options.js.map +1 -1
- package/src/audit.d.ts +7 -57
- package/src/audit.js +101 -301
- package/src/audit.js.map +1 -1
- package/src/babel-plugin-adjust-imports.js +19 -18
- package/src/babel-plugin-adjust-imports.js.map +1 -1
- package/src/babel.d.ts +17 -0
- package/src/babel.js +146 -0
- package/src/babel.js.map +1 -0
- package/src/compat-adapters/@ember-data/store.d.ts +1 -5
- package/src/compat-adapters/@ember-data/store.js +3 -15
- package/src/compat-adapters/@ember-data/store.js.map +1 -1
- package/src/compat-adapters/active-model-adapter.d.ts +1 -1
- package/src/compat-adapters/ember-asset-loader.d.ts +1 -1
- package/src/compat-adapters/ember-cli-addon-docs.d.ts +1 -1
- package/src/compat-adapters/ember-cli-fastboot.js +0 -1
- package/src/compat-adapters/ember-cli-fastboot.js.map +1 -1
- package/src/compat-adapters/ember-cli-mirage.js +0 -1
- package/src/compat-adapters/ember-cli-mirage.js.map +1 -1
- package/src/compat-adapters/ember-decorators.d.ts +1 -1
- package/src/compat-adapters/ember-fetch.d.ts +5 -0
- package/src/compat-adapters/{ember-macro-helpers.js → ember-fetch.js} +5 -4
- package/src/compat-adapters/ember-fetch.js.map +1 -0
- package/src/compat-adapters/ember-percy.d.ts +1 -1
- package/src/compat-adapters/ember-resolver.d.ts +4 -0
- package/src/compat-adapters/ember-resolver.js +21 -0
- package/src/compat-adapters/ember-resolver.js.map +1 -0
- package/src/compat-adapters/ember-scroll-modifiers.d.ts +1 -1
- package/src/compat-adapters/ember-source.d.ts +3 -6
- package/src/compat-adapters/ember-source.js +26 -41
- package/src/compat-adapters/ember-source.js.map +1 -1
- package/src/compat-adapters/ember-test-selectors.d.ts +1 -1
- package/src/compat-addons.js +1 -1
- package/src/compat-addons.js.map +1 -1
- package/src/compat-app-builder.d.ts +9 -67
- package/src/compat-app-builder.js +108 -1299
- package/src/compat-app-builder.js.map +1 -1
- package/src/compat-app.d.ts +4 -22
- package/src/compat-app.js +78 -221
- package/src/compat-app.js.map +1 -1
- package/src/content-for-config.d.ts +11 -0
- package/src/content-for-config.js +66 -0
- package/src/content-for-config.js.map +1 -0
- package/src/default-pipeline.d.ts +4 -5
- package/src/default-pipeline.js +21 -46
- package/src/default-pipeline.js.map +1 -1
- package/src/dependency-rules.d.ts +1 -0
- package/src/dependency-rules.js +19 -11
- package/src/dependency-rules.js.map +1 -1
- package/src/detect-babel-plugins.d.ts +1 -0
- package/src/detect-babel-plugins.js +14 -0
- package/src/detect-babel-plugins.js.map +1 -1
- package/src/http-audit.d.ts +13 -0
- package/src/http-audit.js +60 -0
- package/src/http-audit.js.map +1 -0
- package/src/index.d.ts +2 -2
- package/src/index.js +3 -4
- package/src/index.js.map +1 -1
- package/src/module-visitor.d.ts +52 -0
- package/src/module-visitor.js +285 -0
- package/src/module-visitor.js.map +1 -0
- package/src/options.d.ts +4 -43
- package/src/options.js +35 -8
- package/src/options.js.map +1 -1
- package/src/resolver-transform.d.ts +1 -1
- package/src/resolver-transform.js +71 -43
- package/src/resolver-transform.js.map +1 -1
- package/src/standalone-addon-build.js +6 -15
- package/src/standalone-addon-build.js.map +1 -1
- package/src/v1-addon.js +6 -35
- package/src/v1-addon.js.map +1 -1
- package/src/v1-config.d.ts +0 -8
- package/src/v1-config.js +1 -51
- package/src/v1-config.js.map +1 -1
- package/src/audit-cli.d.ts +0 -2
- package/src/audit-cli.js +0 -150
- package/src/audit-cli.js.map +0 -1
- package/src/compat-adapters/@ember-data/debug.d.ts +0 -6
- package/src/compat-adapters/@ember-data/debug.js +0 -22
- package/src/compat-adapters/@ember-data/debug.js.map +0 -1
- package/src/compat-adapters/ember-macro-helpers.d.ts +0 -4
- package/src/compat-adapters/ember-macro-helpers.js.map +0 -1
- package/src/rename-require-plugin.d.ts +0 -1
- package/src/rename-require-plugin.js +0 -15
- package/src/rename-require-plugin.js.map +0 -1
- package/src/sync-dir.d.ts +0 -8
- package/src/sync-dir.js +0 -68
- package/src/sync-dir.js.map +0 -1
- package/src/template-tag-codemod.d.ts +0 -13
- package/src/template-tag-codemod.js +0 -302
- package/src/template-tag-codemod.js.map +0 -1
- package/src/v1-appboot.d.ts +0 -14
- package/src/v1-appboot.js +0 -47
- package/src/v1-appboot.js.map +0 -1
package/src/options.js
CHANGED
|
@@ -6,22 +6,50 @@ const core_1 = require("@embroider/core");
|
|
|
6
6
|
const defaults = Object.assign((0, core_1.optionsWithDefaults)(), {
|
|
7
7
|
staticAddonTrees: false,
|
|
8
8
|
staticAddonTestSupportTrees: false,
|
|
9
|
-
staticEmberSource: false,
|
|
10
9
|
compatAdapters: new Map(),
|
|
11
10
|
extraPublicTrees: [],
|
|
12
11
|
workspaceDir: null,
|
|
13
12
|
packageRules: [],
|
|
14
13
|
allowUnsafeDynamicComponents: false,
|
|
14
|
+
availableContentForTypes: [],
|
|
15
|
+
useAddonAppBoot: true,
|
|
16
|
+
useAddonConfigModule: true,
|
|
15
17
|
});
|
|
16
18
|
function optionsWithDefaults(options) {
|
|
17
|
-
if (
|
|
18
|
-
|
|
19
|
+
if ((options === null || options === void 0 ? void 0 : options.staticEmberSource) !== undefined) {
|
|
20
|
+
if (options.staticEmberSource === false) {
|
|
21
|
+
throw new Error(`You have set 'staticEmberSource' to 'false' in your Embroider options. This option has been removed is always considered to have the value 'true'. Please remove this setting to continue.`);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
console.log(`You have set 'staticEmberSource' in your Embroider options. This can safely be removed now and it defaults to true.`);
|
|
25
|
+
}
|
|
19
26
|
}
|
|
20
|
-
if (
|
|
21
|
-
|
|
27
|
+
if ((options === null || options === void 0 ? void 0 : options.staticEmberSource) !== undefined) {
|
|
28
|
+
if (options.staticEmberSource === false) {
|
|
29
|
+
throw new Error(`You have set 'staticEmberSource' to 'false' in your Embroider options. This option has been removed is always considered to have the value 'true'. Please remove this setting to continue.`);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
console.log(`You have set 'staticEmberSource' in your Embroider options. This can safely be removed now and it defaults to true.`);
|
|
33
|
+
}
|
|
22
34
|
}
|
|
23
|
-
if (
|
|
24
|
-
|
|
35
|
+
if ((options === null || options === void 0 ? void 0 : options.staticAddonTrees) !== undefined) {
|
|
36
|
+
if (options.staticAddonTrees === false) {
|
|
37
|
+
throw new Error(`You have set 'staticAddonTrees' to 'false' in your Embroider options. This option has been removed is always considered to have the value 'true'. Please remove this setting to continue.`);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
console.log(`You have set 'staticAddonTrees' in your Embroider options. This can safely be removed now and it defaults to true.`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if ((options === null || options === void 0 ? void 0 : options.staticAddonTestSupportTrees) !== undefined) {
|
|
44
|
+
if (options.staticAddonTestSupportTrees === false) {
|
|
45
|
+
throw new Error(`You have set 'staticAddonTestSupportTrees' to 'false' in your Embroider options. This option has been removed is always considered to have the value 'true'. Please remove this setting to continue.`);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
console.log(`You have set 'staticAddonTestSupportTrees' in your Embroider options. This can safely be removed now and it defaults to true.`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
if ((options === null || options === void 0 ? void 0 : options.skipBabel) !== undefined) {
|
|
52
|
+
throw new Error(`You have set 'skipBabel' on your Embroider options. This setting has been removed and you can now configure your babel ignores directly in the babel config in your repo https://babeljs.io/docs/options#ignore`);
|
|
25
53
|
}
|
|
26
54
|
return Object.assign({}, defaults, options);
|
|
27
55
|
}
|
|
@@ -34,7 +62,6 @@ exports.recommendedOptions = Object.freeze({
|
|
|
34
62
|
optimized: Object.freeze({
|
|
35
63
|
staticAddonTrees: true,
|
|
36
64
|
staticAddonTestSupportTrees: true,
|
|
37
|
-
staticEmberSource: true,
|
|
38
65
|
allowUnsafeDynamicComponents: false,
|
|
39
66
|
staticInvokables: true,
|
|
40
67
|
}),
|
package/src/options.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"options.js","sourceRoot":"","sources":["options.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"options.js","sourceRoot":"","sources":["options.ts"],"names":[],"mappings":";;;AAiFA,kDAwDC;AAvID,0CAA0E;AAgE1E,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;IACnC,wBAAwB,EAAE,EAAE;IAC5B,eAAe,EAAE,IAAI;IACrB,oBAAoB,EAAE,IAAI;CAC3B,CAAC,CAAC;AAIH,SAAgB,mBAAmB,CAAC,OAAiB;IACnD,IAAI,CAAC,OAAe,aAAf,OAAO,uBAAP,OAAO,CAAU,iBAAiB,MAAK,SAAS,EAAE,CAAC;QACtD,IAAK,OAAe,CAAC,iBAAiB,KAAK,KAAK,EAAE,CAAC;YACjD,MAAM,IAAI,KAAK,CACb,4LAA4L,CAC7L,CAAC;QACJ,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,GAAG,CACT,qHAAqH,CACtH,CAAC;QACJ,CAAC;IACH,CAAC;IAED,IAAI,CAAC,OAAe,aAAf,OAAO,uBAAP,OAAO,CAAU,iBAAiB,MAAK,SAAS,EAAE,CAAC;QACtD,IAAK,OAAe,CAAC,iBAAiB,KAAK,KAAK,EAAE,CAAC;YACjD,MAAM,IAAI,KAAK,CACb,4LAA4L,CAC7L,CAAC;QACJ,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,GAAG,CACT,qHAAqH,CACtH,CAAC;QACJ,CAAC;IACH,CAAC;IAED,IAAI,CAAC,OAAe,aAAf,OAAO,uBAAP,OAAO,CAAU,gBAAgB,MAAK,SAAS,EAAE,CAAC;QACrD,IAAK,OAAe,CAAC,gBAAgB,KAAK,KAAK,EAAE,CAAC;YAChD,MAAM,IAAI,KAAK,CACb,2LAA2L,CAC5L,CAAC;QACJ,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,GAAG,CACT,oHAAoH,CACrH,CAAC;QACJ,CAAC;IACH,CAAC;IAED,IAAI,CAAC,OAAe,aAAf,OAAO,uBAAP,OAAO,CAAU,2BAA2B,MAAK,SAAS,EAAE,CAAC;QAChE,IAAK,OAAe,CAAC,2BAA2B,KAAK,KAAK,EAAE,CAAC;YAC3D,MAAM,IAAI,KAAK,CACb,sMAAsM,CACvM,CAAC;QACJ,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,GAAG,CACT,+HAA+H,CAChI,CAAC;QACJ,CAAC;IACH,CAAC;IAED,IAAI,CAAC,OAAe,aAAf,OAAO,uBAAP,OAAO,CAAU,SAAS,MAAK,SAAS,EAAE,CAAC;QAC9C,MAAM,IAAI,KAAK,CACb,iNAAiN,CAClN,CAAC;IACJ,CAAC;IAED,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;AAC9C,CAAC;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,4BAA4B,EAAE,KAAK;QACnC,gBAAgB,EAAE,IAAI;KACvB,CAAC;CACH,CAAC,CAAC","sourcesContent":["import type { V1AddonConstructor } from './v1-addon';\nimport type { Options as CoreOptions } from '@embroider/core';\nimport { optionsWithDefaults as coreWithDefaults } from '@embroider/core';\nimport type { 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 // 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 // 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 // Allows you to customize the list of content types addons use to provide HTML\n // to {{content-for}}. By default, the following content types are expected:\n // 'head', 'test-head', 'head-footer', 'test-head-footer', 'body', 'test-body',\n // 'body-footer', 'test-body-footer'. You need to use this config only to extend\n // this list.\n availableContentForTypes?: string[];\n\n // Allows you to cancel the warning that at least one classic addon provides\n // content-for 'app-boot'. This warning brings awareness for developers\n // switching to Embroider, but is no longer necessary once content-for\n // 'app-boot' code has been properly moved to the app-side.\n useAddonAppBoot?: boolean;\n\n // content-for 'config-module'. This warning brings awareness for developers\n // switching to Embroider, but is no longer necessary once content-for\n // 'config-module' code has been properly moved to the app-side.\n useAddonConfigModule?: 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 availableContentForTypes: [],\n useAddonAppBoot: true,\n useAddonConfigModule: true,\n});\n\nexport type CompatOptionsType = Required<Options>;\n\nexport function optionsWithDefaults(options?: Options): CompatOptionsType {\n if ((options as any)?.staticEmberSource !== undefined) {\n if ((options as any).staticEmberSource === false) {\n throw new Error(\n `You have set 'staticEmberSource' to 'false' in your Embroider options. This option has been removed is always considered to have the value 'true'. Please remove this setting to continue.`\n );\n } else {\n console.log(\n `You have set 'staticEmberSource' in your Embroider options. This can safely be removed now and it defaults to true.`\n );\n }\n }\n\n if ((options as any)?.staticEmberSource !== undefined) {\n if ((options as any).staticEmberSource === false) {\n throw new Error(\n `You have set 'staticEmberSource' to 'false' in your Embroider options. This option has been removed is always considered to have the value 'true'. Please remove this setting to continue.`\n );\n } else {\n console.log(\n `You have set 'staticEmberSource' in your Embroider options. This can safely be removed now and it defaults to true.`\n );\n }\n }\n\n if ((options as any)?.staticAddonTrees !== undefined) {\n if ((options as any).staticAddonTrees === false) {\n throw new Error(\n `You have set 'staticAddonTrees' to 'false' in your Embroider options. This option has been removed is always considered to have the value 'true'. Please remove this setting to continue.`\n );\n } else {\n console.log(\n `You have set 'staticAddonTrees' in your Embroider options. This can safely be removed now and it defaults to true.`\n );\n }\n }\n\n if ((options as any)?.staticAddonTestSupportTrees !== undefined) {\n if ((options as any).staticAddonTestSupportTrees === false) {\n throw new Error(\n `You have set 'staticAddonTestSupportTrees' to 'false' in your Embroider options. This option has been removed is always considered to have the value 'true'. Please remove this setting to continue.`\n );\n } else {\n console.log(\n `You have set 'staticAddonTestSupportTrees' in your Embroider options. This can safely be removed now and it defaults to true.`\n );\n }\n }\n\n if ((options as any)?.skipBabel !== undefined) {\n throw new Error(\n `You have set 'skipBabel' on your Embroider options. This setting has been removed and you can now configure your babel ignores directly in the babel config in your repo https://babeljs.io/docs/options#ignore`\n );\n }\n\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 allowUnsafeDynamicComponents: false,\n staticInvokables: true,\n }),\n});\n"]}
|
|
@@ -9,7 +9,7 @@ type Env = WithJSUtils<ASTPluginEnvironment> & {
|
|
|
9
9
|
strictMode?: boolean;
|
|
10
10
|
locals?: string[];
|
|
11
11
|
};
|
|
12
|
-
type UserConfig = Pick<Required<CompatOptions>, '
|
|
12
|
+
type UserConfig = Pick<Required<CompatOptions>, 'staticInvokables' | 'allowUnsafeDynamicComponents'>;
|
|
13
13
|
export interface CompatResolverOptions extends CoreResolverOptions {
|
|
14
14
|
activePackageRules: ActivePackageRules[];
|
|
15
15
|
options: UserConfig;
|
|
@@ -14,7 +14,6 @@ const dependency_rules_1 = require("./dependency-rules");
|
|
|
14
14
|
const typescript_memoize_1 = require("typescript-memoize");
|
|
15
15
|
const assert_never_1 = __importDefault(require("assert-never"));
|
|
16
16
|
const path_1 = require("path");
|
|
17
|
-
const fs_extra_1 = require("fs-extra");
|
|
18
17
|
const dasherize_component_name_1 = require("./dasherize-component-name");
|
|
19
18
|
const core_1 = require("@embroider/core");
|
|
20
19
|
const lodash_1 = require("lodash");
|
|
@@ -96,7 +95,9 @@ class TemplateResolver {
|
|
|
96
95
|
this.scopeStack = new ScopeStack();
|
|
97
96
|
this.visitor = {
|
|
98
97
|
Template: {
|
|
99
|
-
enter: () => {
|
|
98
|
+
enter: (node, path) => {
|
|
99
|
+
this.ownRules = this.findRules(this.env.filename);
|
|
100
|
+
this.implementInvokesRule(node, path);
|
|
100
101
|
if (this.env.locals) {
|
|
101
102
|
this.scopeStack.pushMustacheBlock(this.env.locals);
|
|
102
103
|
}
|
|
@@ -140,7 +141,7 @@ class TemplateResolver {
|
|
|
140
141
|
});
|
|
141
142
|
return;
|
|
142
143
|
}
|
|
143
|
-
let resolution = this.targetComponent(node.path.original);
|
|
144
|
+
let resolution = this.targetComponent(node.path.original, node.path.original);
|
|
144
145
|
this.emit(path, resolution, (node, newId) => {
|
|
145
146
|
node.path = newId;
|
|
146
147
|
});
|
|
@@ -282,7 +283,7 @@ class TemplateResolver {
|
|
|
282
283
|
// if it starts with lower case, it can't be a component we need to
|
|
283
284
|
// globally resolve
|
|
284
285
|
if (node.tag[0] !== node.tag[0].toLowerCase()) {
|
|
285
|
-
resolution = this.targetComponent((0, dasherize_component_name_1.dasherize)(node.tag));
|
|
286
|
+
resolution = this.targetComponent((0, dasherize_component_name_1.dasherize)(node.tag), node.tag);
|
|
286
287
|
}
|
|
287
288
|
this.emit(path, resolution, (node, newId) => {
|
|
288
289
|
node.tag = newId.original;
|
|
@@ -422,20 +423,19 @@ class TemplateResolver {
|
|
|
422
423
|
}
|
|
423
424
|
}
|
|
424
425
|
}
|
|
425
|
-
get
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
get staticModifiersEnabled() {
|
|
432
|
-
return this.config.options.staticModifiers || Boolean(this.auditHandler);
|
|
426
|
+
get staticInvokablesEnabled() {
|
|
427
|
+
var _a;
|
|
428
|
+
if (!((_a = this.config) === null || _a === void 0 ? void 0 : _a.options)) {
|
|
429
|
+
return true;
|
|
430
|
+
}
|
|
431
|
+
return this.config.options.staticInvokables || Boolean(this.auditHandler);
|
|
433
432
|
}
|
|
434
433
|
isIgnoredComponent(dasherizedName) {
|
|
435
434
|
var _a;
|
|
436
435
|
return (_a = this.rules.components.get(dasherizedName)) === null || _a === void 0 ? void 0 : _a.safeToIgnore;
|
|
437
436
|
}
|
|
438
437
|
get rules() {
|
|
438
|
+
var _a, _b;
|
|
439
439
|
// rules that are keyed by the filename they're talking about
|
|
440
440
|
let files = new Map();
|
|
441
441
|
// rules that are keyed by our dasherized interpretation of the component's name
|
|
@@ -443,7 +443,7 @@ class TemplateResolver {
|
|
|
443
443
|
// we're not responsible for filtering out rules for inactive packages here,
|
|
444
444
|
// that is done before getting to us. So we should assume these are all in
|
|
445
445
|
// force.
|
|
446
|
-
for (let rule of this.config.activePackageRules) {
|
|
446
|
+
for (let rule of (_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.activePackageRules) !== null && _b !== void 0 ? _b : []) {
|
|
447
447
|
if (rule.components) {
|
|
448
448
|
for (let [snippet, rules] of Object.entries(rule.components)) {
|
|
449
449
|
let processedRules = (0, dependency_rules_1.preprocessComponentRule)(rules);
|
|
@@ -481,6 +481,9 @@ class TemplateResolver {
|
|
|
481
481
|
return { files, components };
|
|
482
482
|
}
|
|
483
483
|
findRules(absPath) {
|
|
484
|
+
// when babel is invoked by vite our filenames can have query params still
|
|
485
|
+
// hanging off them. That would break rule matching.
|
|
486
|
+
absPath = (0, core_1.cleanUrl)(absPath);
|
|
484
487
|
let fileRules = this.rules.files.get(absPath);
|
|
485
488
|
let componentRules;
|
|
486
489
|
let componentName = this.moduleResolver.reverseComponentLookup(absPath);
|
|
@@ -499,8 +502,8 @@ class TemplateResolver {
|
|
|
499
502
|
}
|
|
500
503
|
return name;
|
|
501
504
|
}
|
|
502
|
-
targetComponent(name) {
|
|
503
|
-
if (!this.
|
|
505
|
+
targetComponent(name, nameHint) {
|
|
506
|
+
if (!this.staticInvokablesEnabled) {
|
|
504
507
|
return null;
|
|
505
508
|
}
|
|
506
509
|
const builtIn = this.builtInsForEmberVersion[name];
|
|
@@ -525,16 +528,17 @@ class TemplateResolver {
|
|
|
525
528
|
let componentRules = this.rules.components.get(name);
|
|
526
529
|
return {
|
|
527
530
|
type: 'component',
|
|
528
|
-
specifier:
|
|
531
|
+
specifier: `@embroider/virtual/components/${name}`,
|
|
529
532
|
importedName: 'default',
|
|
530
533
|
yieldsComponents: componentRules ? componentRules.yieldsSafeComponents : [],
|
|
531
534
|
yieldsArguments: componentRules ? componentRules.yieldsArguments : [],
|
|
532
535
|
argumentsAreComponents: componentRules ? componentRules.argumentsAreComponents : [],
|
|
533
|
-
nameHint: this.nameHint(
|
|
536
|
+
nameHint: this.nameHint(nameHint),
|
|
534
537
|
};
|
|
535
538
|
}
|
|
536
539
|
targetComponentHelper(component, loc, impliedBecause) {
|
|
537
|
-
|
|
540
|
+
var _a;
|
|
541
|
+
if (!this.staticInvokablesEnabled) {
|
|
538
542
|
return null;
|
|
539
543
|
}
|
|
540
544
|
let message;
|
|
@@ -553,8 +557,7 @@ class TemplateResolver {
|
|
|
553
557
|
};
|
|
554
558
|
}
|
|
555
559
|
if (component.type === 'path') {
|
|
556
|
-
|
|
557
|
-
if (ownComponentRules && ownComponentRules.safeInteriorPaths.includes(component.path)) {
|
|
560
|
+
if ((_a = this.ownRules) === null || _a === void 0 ? void 0 : _a.safeInteriorPaths.includes(component.path)) {
|
|
558
561
|
return null;
|
|
559
562
|
}
|
|
560
563
|
return {
|
|
@@ -564,10 +567,10 @@ class TemplateResolver {
|
|
|
564
567
|
loc,
|
|
565
568
|
};
|
|
566
569
|
}
|
|
567
|
-
return this.targetComponent(component.path);
|
|
570
|
+
return this.targetComponent(component.path, component.path);
|
|
568
571
|
}
|
|
569
572
|
targetHelper(path) {
|
|
570
|
-
if (!this.
|
|
573
|
+
if (!this.staticInvokablesEnabled) {
|
|
571
574
|
return null;
|
|
572
575
|
}
|
|
573
576
|
// people are not allowed to override the built-in helpers with their own
|
|
@@ -589,7 +592,7 @@ class TemplateResolver {
|
|
|
589
592
|
}
|
|
590
593
|
return {
|
|
591
594
|
type: 'helper',
|
|
592
|
-
specifier:
|
|
595
|
+
specifier: `@embroider/virtual/helpers/${path}`,
|
|
593
596
|
importedName: 'default',
|
|
594
597
|
nameHint: this.nameHint(path),
|
|
595
598
|
};
|
|
@@ -646,7 +649,7 @@ class TemplateResolver {
|
|
|
646
649
|
it out of their addons.
|
|
647
650
|
*/
|
|
648
651
|
// first, bail out on all the stuff we can obviously ignore
|
|
649
|
-
if (
|
|
652
|
+
if (!this.staticInvokablesEnabled || this.isIgnoredComponent(path)) {
|
|
650
653
|
return null;
|
|
651
654
|
}
|
|
652
655
|
let builtIn = this.builtInsForEmberVersion[path];
|
|
@@ -678,7 +681,7 @@ class TemplateResolver {
|
|
|
678
681
|
if (ownComponentRules === null || ownComponentRules === void 0 ? void 0 : ownComponentRules.disambiguate[path]) {
|
|
679
682
|
switch (ownComponentRules.disambiguate[path]) {
|
|
680
683
|
case 'component':
|
|
681
|
-
return this.targetComponent(path);
|
|
684
|
+
return this.targetComponent(path, path);
|
|
682
685
|
case 'helper':
|
|
683
686
|
return this.targetHelper(path);
|
|
684
687
|
case 'data':
|
|
@@ -698,22 +701,10 @@ class TemplateResolver {
|
|
|
698
701
|
});
|
|
699
702
|
return null;
|
|
700
703
|
}
|
|
701
|
-
// Above we already bailed out if both of these were disabled, so we know at
|
|
702
|
-
// least one is turned on. If both aren't turned on, we're stuck, because we
|
|
703
|
-
// can't even tell if this *is* a component vs a helper.
|
|
704
|
-
if (!this.staticHelpersEnabled || !this.staticComponentsEnabled) {
|
|
705
|
-
this.reportError({
|
|
706
|
-
type: 'error',
|
|
707
|
-
message: 'unsupported ambiguity between helper and component',
|
|
708
|
-
detail: `this use of "{{${path}}}" could be helper "{{ (${path}) }}" or component "<${capitalize((0, lodash_1.camelCase)(path))} />", and your settings for staticHelpers and staticComponents do not agree. Either switch to one of the unambiguous forms, or make staticHelpers and staticComponents agree, or use a "disambiguate" packageRule to work around the problem if its in third-party code you cannot easily fix.`,
|
|
709
|
-
loc,
|
|
710
|
-
});
|
|
711
|
-
return null;
|
|
712
|
-
}
|
|
713
704
|
let componentRules = this.rules.components.get(path);
|
|
714
705
|
return {
|
|
715
706
|
type: 'component',
|
|
716
|
-
specifier:
|
|
707
|
+
specifier: `@embroider/virtual/ambiguous/${path}`,
|
|
717
708
|
importedName: 'default',
|
|
718
709
|
yieldsComponents: componentRules ? componentRules.yieldsSafeComponents : [],
|
|
719
710
|
yieldsArguments: componentRules ? componentRules.yieldsArguments : [],
|
|
@@ -722,7 +713,7 @@ class TemplateResolver {
|
|
|
722
713
|
};
|
|
723
714
|
}
|
|
724
715
|
targetElementModifier(path) {
|
|
725
|
-
if (!this.
|
|
716
|
+
if (!this.staticInvokablesEnabled) {
|
|
726
717
|
return null;
|
|
727
718
|
}
|
|
728
719
|
const builtIn = this.builtInsForEmberVersion[path];
|
|
@@ -740,13 +731,13 @@ class TemplateResolver {
|
|
|
740
731
|
}
|
|
741
732
|
return {
|
|
742
733
|
type: 'modifier',
|
|
743
|
-
specifier:
|
|
734
|
+
specifier: `@embroider/virtual/modifiers/${path}`,
|
|
744
735
|
importedName: 'default',
|
|
745
736
|
nameHint: this.nameHint(path),
|
|
746
737
|
};
|
|
747
738
|
}
|
|
748
739
|
targetDynamicModifier(modifier, loc) {
|
|
749
|
-
if (!this.
|
|
740
|
+
if (!this.staticInvokablesEnabled) {
|
|
750
741
|
return null;
|
|
751
742
|
}
|
|
752
743
|
if (modifier.type === 'literal') {
|
|
@@ -762,7 +753,7 @@ class TemplateResolver {
|
|
|
762
753
|
}
|
|
763
754
|
}
|
|
764
755
|
targetDynamicHelper(helper) {
|
|
765
|
-
if (!this.
|
|
756
|
+
if (!this.staticInvokablesEnabled) {
|
|
766
757
|
return null;
|
|
767
758
|
}
|
|
768
759
|
if (helper.type === 'literal') {
|
|
@@ -799,13 +790,36 @@ class TemplateResolver {
|
|
|
799
790
|
}
|
|
800
791
|
return null;
|
|
801
792
|
}
|
|
793
|
+
implementInvokesRule(node, path) {
|
|
794
|
+
var _a;
|
|
795
|
+
if (!((_a = this.ownRules) === null || _a === void 0 ? void 0 : _a.invokes)) {
|
|
796
|
+
return;
|
|
797
|
+
}
|
|
798
|
+
let registrations = [];
|
|
799
|
+
for (let snippets of Object.values(this.ownRules.invokes)) {
|
|
800
|
+
for (let snippet of snippets) {
|
|
801
|
+
let dasherizedName = (0, dasherize_component_name_1.snippetToDasherizedName)(snippet);
|
|
802
|
+
if (!dasherizedName) {
|
|
803
|
+
throw new Error(`Package rule contains unparseable component snippet: ${snippet}`);
|
|
804
|
+
}
|
|
805
|
+
let resolution = this.targetComponentHelper({ type: 'literal', path: dasherizedName }, node.loc);
|
|
806
|
+
this.emit(path, resolution, (_target, id) => {
|
|
807
|
+
registrations.push(this.env.syntax.builders.pair(dasherizedName, id));
|
|
808
|
+
});
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
if (registrations.length > 0) {
|
|
812
|
+
node.body.unshift(this.env.syntax.builders.mustache(this.env.meta.jsutils.bindExpression(registrationHelper, path, { nameHint: 'registerComponents' }), [], this.env.syntax.builders.hash(registrations)));
|
|
813
|
+
}
|
|
814
|
+
}
|
|
802
815
|
}
|
|
803
816
|
__decorate([
|
|
804
817
|
(0, typescript_memoize_1.Memoize)()
|
|
805
818
|
], TemplateResolver.prototype, "rules", null);
|
|
806
819
|
// This is the AST transform that resolves components, helpers and modifiers at build time
|
|
807
820
|
function makeResolverTransform({ appRoot, emberVersion, externalNameHint }) {
|
|
808
|
-
let
|
|
821
|
+
let loader = new core_1.ResolverLoader(appRoot);
|
|
822
|
+
let config = loader.resolver.options;
|
|
809
823
|
const resolverTransform = env => {
|
|
810
824
|
if (env.strictMode) {
|
|
811
825
|
return {
|
|
@@ -985,4 +999,18 @@ function parts(path) {
|
|
|
985
999
|
return;
|
|
986
1000
|
return 'original' in path ? path.original.split('.') : path.parts;
|
|
987
1001
|
}
|
|
1002
|
+
function registrationHelper(context) {
|
|
1003
|
+
let Helper = context.import('@ember/component/helper', 'default', 'Helper');
|
|
1004
|
+
let getOwner = context.import('@ember/owner', 'getOwner');
|
|
1005
|
+
return `
|
|
1006
|
+
(class extends ${Helper} {
|
|
1007
|
+
compute(_positional, registrations) {
|
|
1008
|
+
let owner = ${getOwner}(this);
|
|
1009
|
+
for (let [name, definition] of Object.entries(registrations)) {
|
|
1010
|
+
owner.register(\`component:\${name}\`, definition);
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1013
|
+
})
|
|
1014
|
+
`;
|
|
1015
|
+
}
|
|
988
1016
|
//# sourceMappingURL=resolver-transform.js.map
|