@embroider/addon-dev 3.2.1-unstable.b8ac17b → 4.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@embroider/addon-dev",
3
- "version": "3.2.1-unstable.b8ac17b",
3
+ "version": "4.0.0",
4
4
  "description": "Utilities for addon authors",
5
5
  "repository": {
6
6
  "type": "git",
@@ -22,35 +22,34 @@
22
22
  "src/**/*.d.ts",
23
23
  "src/**/*.js.map"
24
24
  ],
25
- "scripts": {
26
- "test": "jest"
27
- },
28
25
  "dependencies": {
29
- "@embroider/core": "3.2.1-unstable.b8ac17b",
30
26
  "@rollup/pluginutils": "^4.1.1",
31
- "assert-never": "^1.2.1",
32
27
  "content-tag": "^1.0.0",
33
28
  "fs-extra": "^10.0.0",
34
29
  "minimatch": "^3.0.4",
35
30
  "rollup-plugin-copy-assets": "^2.0.3",
36
31
  "rollup-plugin-delete": "^2.0.0",
37
32
  "walk-sync": "^3.0.0",
38
- "yargs": "^17.0.1"
33
+ "yargs": "^17.0.1",
34
+ "@embroider/core": "^3.2.1"
39
35
  },
40
36
  "devDependencies": {
41
- "@embroider/test-support": "workspace:*",
42
37
  "@glimmer/syntax": "^0.84.2",
43
38
  "@types/fs-extra": "^9.0.12",
44
39
  "@types/minimatch": "^3.0.4",
45
40
  "@types/yargs": "^17.0.3",
46
41
  "rollup": "^3.23.0",
47
42
  "tmp": "^0.1.0",
48
- "typescript": "^5.1.6"
43
+ "typescript": "^5.1.6",
44
+ "@embroider/test-support": "0.36.0"
49
45
  },
50
46
  "engines": {
51
47
  "node": "12.* || 14.* || >= 16"
52
48
  },
53
49
  "volta": {
54
50
  "extends": "../../package.json"
51
+ },
52
+ "scripts": {
53
+ "test": "jest"
55
54
  }
56
- }
55
+ }
@@ -9,23 +9,12 @@ const processor = new content_tag_1.Preprocessor();
9
9
  function rollupGjsPlugin() {
10
10
  return {
11
11
  name: PLUGIN_NAME,
12
- async resolveId(source, importer, options) {
13
- let resolution = await this.resolve(source, importer, {
14
- skipSelf: true,
15
- ...options,
16
- });
17
- if (resolution) {
18
- return maybeRewriteGJS(resolution);
19
- }
20
- },
21
12
  load(id) {
22
- const meta = getMeta(this, id);
23
- if (!meta) {
24
- return;
13
+ if (!gjsFilter(id)) {
14
+ return null;
25
15
  }
26
- this.addWatchFile(meta.originalId);
27
- let input = (0, fs_1.readFileSync)(meta.originalId, 'utf8');
28
- let code = processor.process(input);
16
+ let input = (0, fs_1.readFileSync)(id, 'utf8');
17
+ let code = processor.process(input, id);
29
18
  return {
30
19
  code,
31
20
  };
@@ -33,40 +22,5 @@ function rollupGjsPlugin() {
33
22
  };
34
23
  }
35
24
  exports.default = rollupGjsPlugin;
36
- function getMeta(context, id) {
37
- var _a, _b;
38
- const meta = (_b = (_a = context.getModuleInfo(id)) === null || _a === void 0 ? void 0 : _a.meta) === null || _b === void 0 ? void 0 : _b[PLUGIN_NAME];
39
- if (meta) {
40
- return meta;
41
- }
42
- else {
43
- return null;
44
- }
45
- }
46
25
  const gjsFilter = (0, pluginutils_1.createFilter)('**/*.g{j,t}s');
47
- function maybeRewriteGJS(resolution) {
48
- if (!gjsFilter(resolution.id)) {
49
- return null;
50
- }
51
- let id;
52
- if (resolution.id.endsWith('.gjs')) {
53
- id = resolution.id.replace(/\.gjs$/, '.js');
54
- }
55
- else if (resolution.id.endsWith('.gts')) {
56
- id = resolution.id.replace(/\.gts$/, '.ts');
57
- }
58
- else {
59
- throw new Error('Unexpected issues in the plugin-rollup-gjs - an unexpected file made its way throught the pluginUtils filter');
60
- }
61
- // This creates an `*.js` or `*.ts` that **replaces** the .gjs or .gts file that we will populate in `load()` hook.
62
- return {
63
- ...resolution,
64
- id,
65
- meta: {
66
- [PLUGIN_NAME]: {
67
- originalId: resolution.id,
68
- },
69
- },
70
- };
71
- }
72
26
  //# sourceMappingURL=rollup-gjs-plugin.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"rollup-gjs-plugin.js","sourceRoot":"","sources":["rollup-gjs-plugin.ts"],"names":[],"mappings":";;AAAA,qDAAmD;AAEnD,2BAAkC;AAClC,6CAA2C;AAE3C,MAAM,WAAW,GAAG,mBAAmB,CAAC;AAExC,MAAM,SAAS,GAAG,IAAI,0BAAY,EAAE,CAAC;AACrC,6CAA6C;AAE7C,SAAwB,eAAe;IACrC,OAAO;QACL,IAAI,EAAE,WAAW;QACjB,KAAK,CAAC,SAAS,CAAC,MAAc,EAAE,QAA4B,EAAE,OAAO;YACnE,IAAI,UAAU,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,QAAQ,EAAE;gBACpD,QAAQ,EAAE,IAAI;gBACd,GAAG,OAAO;aACX,CAAC,CAA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AC,EAAE,CAAC,OAAO,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;KAC7C;SAAM;QACL,MAAM,IAAI,KAAK,CACb,8GAA8G,CAC/G,CAAC;KACH;IAED,mHAAmH;IACnH,OAAO;QACL,GAAG,UAAU;QACb,EAAE;QACF,IAAI,EAAE;YACJ,CAAC,WAAW,CAAC,EAAE;gBACb,UAAU,EAAE,UAAU,CAAC,EAAE;aAC1B;SACF;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { createFilter } from '@rollup/pluginutils';\nimport type { Plugin, PluginContext, ResolvedId } from 'rollup';\nimport { readFileSync } from 'fs';\nimport { Preprocessor } from 'content-tag';\n\nconst PLUGIN_NAME = 'rollup-gjs-plugin';\n\nconst processor = new Preprocessor();\n// import { parse as pathParse } from 'path';\n\nexport default function rollupGjsPlugin(): Plugin {\n return {\n name: PLUGIN_NAME,\n async resolveId(source: string, importer: string | undefined, options) {\n let resolution = await this.resolve(source, importer, {\n skipSelf: true,\n ...options,\n });\n\n if (resolution) {\n return maybeRewriteGJS(resolution);\n }\n },\n\n load(id: string) {\n const meta = getMeta(this, id);\n if (!meta) {\n return;\n }\n\n this.addWatchFile(meta.originalId);\n let input = readFileSync(meta.originalId, 'utf8');\n let code = processor.process(input);\n return {\n code,\n };\n },\n };\n}\n\ntype Meta = {\n originalId: string;\n};\n\nfunction getMeta(context: PluginContext, id: string): Meta | null {\n const meta = context.getModuleInfo(id)?.meta?.[PLUGIN_NAME];\n if (meta) {\n return meta as Meta;\n } else {\n return null;\n }\n}\n\nconst gjsFilter = createFilter('**/*.g{j,t}s');\n\nfunction maybeRewriteGJS(resolution: ResolvedId) {\n if (!gjsFilter(resolution.id)) {\n return null;\n }\n\n let id;\n\n if (resolution.id.endsWith('.gjs')) {\n id = resolution.id.replace(/\\.gjs$/, '.js');\n } else if (resolution.id.endsWith('.gts')) {\n id = resolution.id.replace(/\\.gts$/, '.ts');\n } else {\n throw new Error(\n 'Unexpected issues in the plugin-rollup-gjs - an unexpected file made its way throught the pluginUtils filter'\n );\n }\n\n // This creates an `*.js` or `*.ts` that **replaces** the .gjs or .gts file that we will populate in `load()` hook.\n return {\n ...resolution,\n id,\n meta: {\n [PLUGIN_NAME]: {\n originalId: resolution.id,\n },\n },\n };\n}\n"]}
1
+ {"version":3,"file":"rollup-gjs-plugin.js","sourceRoot":"","sources":["rollup-gjs-plugin.ts"],"names":[],"mappings":";;AAAA,qDAAmD;AAEnD,2BAAkC;AAClC,6CAA2C;AAE3C,MAAM,WAAW,GAAG,mBAAmB,CAAC;AAExC,MAAM,SAAS,GAAG,IAAI,0BAAY,EAAE,CAAC;AACrC,6CAA6C;AAE7C,SAAwB,eAAe;IACrC,OAAO;QACL,IAAI,EAAE,WAAW;QAEjB,IAAI,CAAC,EAAU;YACb,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,EAAE;gBAClB,OAAO,IAAI,CAAC;aACb;YACD,IAAI,KAAK,GAAG,IAAA,iBAAY,EAAC,EAAE,EAAE,MAAM,CAAC,CAAC;YACrC,IAAI,IAAI,GAAG,SAAS,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;YACxC,OAAO;gBACL,IAAI;aACL,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC;AAfD,kCAeC;AAED,MAAM,SAAS,GAAG,IAAA,0BAAY,EAAC,cAAc,CAAC,CAAC","sourcesContent":["import { createFilter } from '@rollup/pluginutils';\nimport type { Plugin } from 'rollup';\nimport { readFileSync } from 'fs';\nimport { Preprocessor } from 'content-tag';\n\nconst PLUGIN_NAME = 'rollup-gjs-plugin';\n\nconst processor = new Preprocessor();\n// import { parse as pathParse } from 'path';\n\nexport default function rollupGjsPlugin(): Plugin {\n return {\n name: PLUGIN_NAME,\n\n load(id: string) {\n if (!gjsFilter(id)) {\n return null;\n }\n let input = readFileSync(id, 'utf8');\n let code = processor.process(input, id);\n return {\n code,\n };\n },\n };\n}\n\nconst gjsFilter = createFilter('**/*.g{j,t}s');\n"]}
@@ -1,12 +1,8 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  const pluginutils_1 = require("@rollup/pluginutils");
7
4
  const fs_1 = require("fs");
8
5
  const core_1 = require("@embroider/core");
9
- const assert_never_1 = __importDefault(require("assert-never"));
10
6
  const path_1 = require("path");
11
7
  function rollupHbsPlugin() {
12
8
  return {
@@ -16,32 +12,25 @@ function rollupHbsPlugin() {
16
12
  skipSelf: true,
17
13
  ...options,
18
14
  });
19
- if (!resolution) {
20
- return maybeSynthesizeComponentJS(this, source, importer, options);
15
+ if (resolution) {
16
+ return resolution;
21
17
  }
22
18
  else {
23
- return maybeRewriteHBS(resolution);
19
+ return maybeSynthesizeComponentJS(this, source, importer, options);
24
20
  }
25
21
  },
26
22
  load(id) {
27
- const meta = getMeta(this, id);
28
- if (!meta) {
29
- return;
23
+ if (hbsFilter(id)) {
24
+ let input = (0, fs_1.readFileSync)(id, 'utf8');
25
+ let code = (0, core_1.hbsToJS)(input);
26
+ return {
27
+ code,
28
+ };
30
29
  }
31
- switch (meta.type) {
32
- case 'template':
33
- this.addWatchFile(meta.originalId);
34
- let input = (0, fs_1.readFileSync)(meta.originalId, 'utf8');
35
- let code = (0, core_1.hbsToJS)(input);
36
- return {
37
- code,
38
- };
39
- case 'template-only-component-js':
40
- return {
41
- code: templateOnlyComponent,
42
- };
43
- default:
44
- (0, assert_never_1.default)(meta);
30
+ if (getMeta(this, id)) {
31
+ return {
32
+ code: templateOnlyComponent,
33
+ };
45
34
  }
46
35
  },
47
36
  };
@@ -83,20 +72,4 @@ async function maybeSynthesizeComponentJS(context, source, importer, options) {
83
72
  };
84
73
  }
85
74
  const hbsFilter = (0, pluginutils_1.createFilter)('**/*.hbs');
86
- function maybeRewriteHBS(resolution) {
87
- if (!hbsFilter(resolution.id)) {
88
- return null;
89
- }
90
- // This creates an `*.hbs.js` that we will populate in `load()` hook.
91
- return {
92
- ...resolution,
93
- id: resolution.id + '.js',
94
- meta: {
95
- 'rollup-hbs-plugin': {
96
- type: 'template',
97
- originalId: resolution.id,
98
- },
99
- },
100
- };
101
- }
102
75
  //# sourceMappingURL=rollup-hbs-plugin.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"rollup-hbs-plugin.js","sourceRoot":"","sources":["rollup-hbs-plugin.ts"],"names":[],"mappings":";;;;;AAAA,qDAAmD;AAOnD,2BAAkC;AAClC,0CAA0C;AAC1C,gEAAuC;AACvC,+BAA0C;AAE1C,SAAwB,eAAe;IACrC,OAAO;QACL,IAAI,EAAE,mBAAmB;QACzB,KAAK,CAAC,SAAS,CAAC,MAAc,EAAE,QAA4B,EAAE,OAAO;YACnE,IAAI,UAAU,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,QAAQ,EAAE;gBACpD,QAAQ,EAAE,IAAI;gBACd,GAAG,OAAO;aACX,CAAC,CAAC;YAEH,IAAI,CAAC,UAAU,EAAE;gBACf,OAAO,0BAA0B,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;aACpE;iBAAM;gBACL,OAAO,eAAe,CAAC,UAAU,CAAC,CAAC;aACpC;QACH,CAAC;QAED,IAAI,CAAC,EAAU;YACb,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;YAC/B,IAAI,CAAC,IAAI,EAAE;gBACT,OAAO;aACR;YAED,QAAQ,IAAI,CAAC,IAAI,EAAE;gBACjB,KAAK,UAAU;oBACb,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;oBACnC,IAAI,KAAK,GAAG,IAAA,iBAAY,EAAC,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;oBAClD,IAAI,IAAI,GAAG,IAAA,cAAO,EAAC,KAAK,CAAC,CAAC;oBAC1B,OAAO;wBACL,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B;aACnC;SACF;KACF,CAAC;AACJ,CAAC;AAED,MAAM,SAAS,GAAG,IAAA,0BAAY,EAAC,UAAU,CAAC,CAAC;AAE3C,SAAS,eAAe,CAAC,UAAsB;IAC7C,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE,CAAC,EAAE;QAC7B,OAAO,IAAI,CAAC;KACb;IAED,qEAAqE;IACrE,OAAO;QACL,GAAG,UAAU;QACb,EAAE,EAAE,UAAU,CAAC,EAAE,GAAG,KAAK;QACzB,IAAI,EAAE;YACJ,mBAAmB,EAAE;gBACnB,IAAI,EAAE,UAAU;gBAChB,UAAU,EAAE,UAAU,CAAC,EAAE;aAC1B;SACF;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { createFilter } from '@rollup/pluginutils';\nimport type {\n Plugin,\n PluginContext,\n CustomPluginOptions,\n ResolvedId,\n} from 'rollup';\nimport { readFileSync } from 'fs';\nimport { hbsToJS } from '@embroider/core';\nimport assertNever from 'assert-never';\nimport { parse as pathParse } from 'path';\n\nexport default function rollupHbsPlugin(): Plugin {\n return {\n name: 'rollup-hbs-plugin',\n async resolveId(source: string, importer: string | undefined, options) {\n let resolution = await this.resolve(source, importer, {\n skipSelf: true,\n ...options,\n });\n\n if (!resolution) {\n return maybeSynthesizeComponentJS(this, source, importer, options);\n } else {\n return maybeRewriteHBS(resolution);\n }\n },\n\n load(id: string) {\n const meta = getMeta(this, id);\n if (!meta) {\n return;\n }\n\n switch (meta.type) {\n case 'template':\n this.addWatchFile(meta.originalId);\n let input = readFileSync(meta.originalId, 'utf8');\n let code = hbsToJS(input);\n return {\n code,\n };\n case 'template-only-component-js':\n return {\n code: templateOnlyComponent,\n };\n default:\n assertNever(meta);\n }\n },\n };\n}\n\nconst templateOnlyComponent =\n `import templateOnly from '@ember/component/template-only';\\n` +\n `export default templateOnly();\\n`;\n\ntype Meta =\n | {\n type: 'template';\n originalId: string;\n }\n | {\n type: 'template-only-component-js';\n };\n\nfunction getMeta(context: PluginContext, id: string): Meta | null {\n const meta = context.getModuleInfo(id)?.meta?.['rollup-hbs-plugin'];\n if (meta) {\n return meta as Meta;\n } else {\n return null;\n }\n}\n\nfunction correspondingTemplate(filename: string): string {\n let { ext } = pathParse(filename);\n return filename.slice(0, filename.length - ext.length) + '.hbs';\n}\n\nasync function maybeSynthesizeComponentJS(\n context: PluginContext,\n source: string,\n importer: string | undefined,\n options: { custom?: CustomPluginOptions; isEntry: boolean }\n) {\n let templateResolution = await context.resolve(\n correspondingTemplate(source),\n importer,\n {\n skipSelf: true,\n ...options,\n }\n );\n if (!templateResolution) {\n return null;\n }\n // we're trying to resolve a JS module but only the corresponding HBS\n // file exists. Synthesize the template-only component JS.\n return {\n id: templateResolution.id.replace(/\\.hbs$/, '.js'),\n meta: {\n 'rollup-hbs-plugin': {\n type: 'template-only-component-js',\n },\n },\n };\n}\n\nconst hbsFilter = createFilter('**/*.hbs');\n\nfunction maybeRewriteHBS(resolution: ResolvedId) {\n if (!hbsFilter(resolution.id)) {\n return null;\n }\n\n // This creates an `*.hbs.js` that we will populate in `load()` hook.\n return {\n ...resolution,\n id: resolution.id + '.js',\n meta: {\n 'rollup-hbs-plugin': {\n type: 'template',\n originalId: resolution.id,\n },\n },\n };\n}\n"]}
1
+ {"version":3,"file":"rollup-hbs-plugin.js","sourceRoot":"","sources":["rollup-hbs-plugin.ts"],"names":[],"mappings":";;AAAA,qDAAmD;AAEnD,2BAAkC;AAClC,0CAA0C;AAC1C,+BAA0C;AAE1C,SAAwB,eAAe;IACrC,OAAO;QACL,IAAI,EAAE,mBAAmB;QACzB,KAAK,CAAC,SAAS,CAAC,MAAc,EAAE,QAA4B,EAAE,OAAO;YACnE,IAAI,UAAU,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,QAAQ,EAAE;gBACpD,QAAQ,EAAE,IAAI;gBACd,GAAG,OAAO;aACX,CAAC,CAAC;YAEH,IAAI,UAAU,EAAE;gBACd,OAAO,UAAU,CAAC;aACnB;iBAAM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;QACE,QAAQ,EAAE,IAAI;QACd,GAAG,OAAO;KACX,CACF,CAAC;IACF,IAAI,CAAC,kBAAkB,EAAE;QACvB,OAAO,IAAI,CAAC;KACb;IACD,qEAAqE;IACrE,0DAA0D;IAC1D,OAAO;QACL,EAAE,EAAE,kBAAkB,CAAC,EAAE,CAAC,OAAO,CAAC,QAAQ,EAAE,KAAK,CAAC;QAClD,IAAI,EAAE;YACJ,mBAAmB,EAAE;gBACnB,IAAI,EAAE,4BAA4B;aACnC;SACF;KACF,CAAC;AACJ,CAAC;AAED,MAAM,SAAS,GAAG,IAAA,0BAAY,EAAC,UAAU,CAAC,CAAC","sourcesContent":["import { createFilter } from '@rollup/pluginutils';\nimport type { Plugin, PluginContext, CustomPluginOptions } from 'rollup';\nimport { readFileSync } from 'fs';\nimport { hbsToJS } from '@embroider/core';\nimport { parse as pathParse } from 'path';\n\nexport default function rollupHbsPlugin(): Plugin {\n return {\n name: 'rollup-hbs-plugin',\n async resolveId(source: string, importer: string | undefined, options) {\n let resolution = await this.resolve(source, importer, {\n skipSelf: true,\n ...options,\n });\n\n if (resolution) {\n return resolution;\n } else {\n return maybeSynthesizeComponentJS(this, source, importer, options);\n }\n },\n\n load(id: string) {\n if (hbsFilter(id)) {\n let input = readFileSync(id, 'utf8');\n let code = hbsToJS(input);\n return {\n code,\n };\n }\n if (getMeta(this, id)) {\n return {\n code: templateOnlyComponent,\n };\n }\n },\n };\n}\n\nconst templateOnlyComponent =\n `import templateOnly from '@ember/component/template-only';\\n` +\n `export default templateOnly();\\n`;\n\ntype Meta = {\n type: 'template-only-component-js';\n};\n\nfunction getMeta(context: PluginContext, id: string): Meta | null {\n const meta = context.getModuleInfo(id)?.meta?.['rollup-hbs-plugin'];\n if (meta) {\n return meta as Meta;\n } else {\n return null;\n }\n}\n\nfunction correspondingTemplate(filename: string): string {\n let { ext } = pathParse(filename);\n return filename.slice(0, filename.length - ext.length) + '.hbs';\n}\n\nasync function maybeSynthesizeComponentJS(\n context: PluginContext,\n source: string,\n importer: string | undefined,\n options: { custom?: CustomPluginOptions; isEntry: boolean }\n) {\n let templateResolution = await context.resolve(\n correspondingTemplate(source),\n importer,\n {\n skipSelf: true,\n ...options,\n }\n );\n if (!templateResolution) {\n return null;\n }\n // we're trying to resolve a JS module but only the corresponding HBS\n // file exists. Synthesize the template-only component JS.\n return {\n id: templateResolution.id.replace(/\\.hbs$/, '.js'),\n meta: {\n 'rollup-hbs-plugin': {\n type: 'template-only-component-js',\n },\n },\n };\n}\n\nconst hbsFilter = createFilter('**/*.hbs');\n"]}