@embroider/addon-dev 7.1.2-unstable.1c0f616 → 7.1.2-unstable.a4178fb
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/addon-dev",
|
|
3
|
-
"version": "7.1.2-unstable.
|
|
3
|
+
"version": "7.1.2-unstable.a4178fb",
|
|
4
4
|
"description": "Utilities for addon authors",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"rollup-plugin-copy-assets": "^2.0.3",
|
|
40
40
|
"walk-sync": "^3.0.0",
|
|
41
41
|
"yargs": "^17.0.1",
|
|
42
|
-
"@embroider/core": "^3.5.1-unstable.
|
|
42
|
+
"@embroider/core": "^3.5.1-unstable.a4178fb"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@glimmer/syntax": "^0.84.2",
|
|
@@ -6,19 +6,47 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.default = keepAssets;
|
|
7
7
|
const minimatch_1 = __importDefault(require("minimatch"));
|
|
8
8
|
const path_1 = require("path");
|
|
9
|
+
const fs_1 = require("fs");
|
|
9
10
|
// randomly chosen, we're just looking to have high-entropy identifiers that
|
|
10
11
|
// won't collide with anyting else in the source
|
|
11
12
|
let counter = 11559;
|
|
12
13
|
function keepAssets({ from, include, exports, }) {
|
|
13
|
-
const marker = `
|
|
14
|
+
const marker = `__keep_assets_marker_${counter++}__`;
|
|
14
15
|
return {
|
|
15
|
-
name: '
|
|
16
|
+
name: 'keep-assets',
|
|
17
|
+
// we implement a load hook for the assets we're keeping so that we can
|
|
18
|
+
// capture their true binary representations. If we fell through to the
|
|
19
|
+
// default rollup load hook we would get utf8 interpretations of them.
|
|
20
|
+
//
|
|
21
|
+
// Our plugin should be placed after any other plugins that have their own
|
|
22
|
+
// load hooks, in which case this will not run but our transform hook will
|
|
23
|
+
// still over from there.
|
|
24
|
+
load(id) {
|
|
25
|
+
if (include.some((pattern) => (0, minimatch_1.default)(id, pattern))) {
|
|
26
|
+
return {
|
|
27
|
+
code: (0, fs_1.readFileSync)(id).toString('binary'),
|
|
28
|
+
meta: {
|
|
29
|
+
'keep-assets': {
|
|
30
|
+
binaryLoaded: true,
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
},
|
|
16
36
|
transform(code, id) {
|
|
37
|
+
var _a, _b;
|
|
38
|
+
let output = code;
|
|
39
|
+
let ourMeta = (_b = (_a = this.getModuleInfo(id)) === null || _a === void 0 ? void 0 : _a.meta) === null || _b === void 0 ? void 0 : _b['keep-assets'];
|
|
40
|
+
if (ourMeta === null || ourMeta === void 0 ? void 0 : ourMeta.binaryLoaded) {
|
|
41
|
+
// when the code was produced by our own load hook it is binary-encoded
|
|
42
|
+
// string and we can emit the true bytes.
|
|
43
|
+
output = Buffer.from(code, 'binary');
|
|
44
|
+
}
|
|
17
45
|
if (include.some((pattern) => (0, minimatch_1.default)(id, pattern))) {
|
|
18
46
|
let ref = this.emitFile({
|
|
19
47
|
type: 'asset',
|
|
20
48
|
fileName: (0, path_1.relative)(from, id),
|
|
21
|
-
source:
|
|
49
|
+
source: output,
|
|
22
50
|
});
|
|
23
51
|
if (exports === '*') {
|
|
24
52
|
return `export * from ${marker}("${ref}")`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rollup-keep-assets.js","sourceRoot":"","sources":["rollup-keep-assets.ts"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"rollup-keep-assets.js","sourceRoot":"","sources":["rollup-keep-assets.ts"],"names":[],"mappings":";;;;;AASA,6BAyEC;AAjFD,0DAAkC;AAClC,+BAAyC;AACzC,2BAAkC;AAElC,4EAA4E;AAC5E,gDAAgD;AAChD,IAAI,OAAO,GAAG,KAA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,EAAE,CAAC;YAC1B,OAAO,MAAM,CAAC,GAAG,CAAC,SAAS,CAAE,CAAC;QAChC,CAAC;QACD,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,MAAM,CAAC,GAAG,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;YACjC,OAAO,SAAS,CAAC;QACnB,CAAC;QACD,OAAO,IAAI,EAAE,CAAC;YACZ,IAAI,SAAS,GAAG,UAAU,OAAO,EAAE,GAAG,CAAC;YACvC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC;gBAC9B,MAAM,CAAC,GAAG,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;gBACjC,OAAO,SAAS,CAAC;YACnB,CAAC;QACH,CAAC;IACH,CAAC;IAED,SAAS,OAAO;QACd,OAAO,CACL,CAAC,GAAG,MAAM,CAAC;aACR,GAAG,CAAC,CAAC,CAAC,SAAS,EAAE,YAAY,CAAC,EAAE,EAAE;YACjC,IAAI,YAAY,EAAE,CAAC;gBACjB,OAAO,UAAU,YAAY,UAAU,SAAS,GAAG,CAAC;YACtD,CAAC;iBAAM,CAAC;gBACN,OAAO,WAAW,SAAS,GAAG,CAAC;YACjC,CAAC;QACH,CAAC,CAAC;aACD,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CACrB,CAAC;IACJ,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC;AAC9B,CAAC","sourcesContent":["import type { Plugin } from 'rollup';\nimport minimatch from 'minimatch';\nimport { dirname, relative } from 'path';\nimport { readFileSync } from 'fs';\n\n// randomly chosen, we're just looking to have high-entropy identifiers that\n// won't collide with anyting else in the source\nlet counter = 11559;\n\nexport default function keepAssets({\n from,\n include,\n exports,\n}: {\n from: string;\n include: string[];\n exports?: undefined | 'default' | '*';\n}): Plugin {\n const marker = `__keep_assets_marker_${counter++}__`;\n\n return {\n name: 'keep-assets',\n\n // we implement a load hook for the assets we're keeping so that we can\n // capture their true binary representations. If we fell through to the\n // default rollup load hook we would get utf8 interpretations of them.\n //\n // Our plugin should be placed after any other plugins that have their own\n // load hooks, in which case this will not run but our transform hook will\n // still over from there.\n load(id: string) {\n if (include.some((pattern) => minimatch(id, pattern))) {\n return {\n code: readFileSync(id).toString('binary'),\n meta: {\n 'keep-assets': {\n binaryLoaded: true,\n },\n },\n };\n }\n },\n\n transform(code: string, id: string) {\n let output: Buffer | string = code;\n let ourMeta = this.getModuleInfo(id)?.meta?.['keep-assets'];\n if (ourMeta?.binaryLoaded) {\n // when the code was produced by our own load hook it is binary-encoded\n // string and we can emit the true bytes.\n output = Buffer.from(code, 'binary');\n }\n if (include.some((pattern) => minimatch(id, pattern))) {\n let ref = this.emitFile({\n type: 'asset',\n fileName: relative(from, id),\n source: output,\n });\n if (exports === '*') {\n return `export * from ${marker}(\"${ref}\")`;\n } else if (exports === 'default') {\n return `export default ${marker}(\"${ref}\")`;\n } else {\n // side-effect only\n return `${marker}(\"${ref}\")`;\n }\n }\n },\n renderChunk(code, chunk) {\n const { getName, imports } = nameTracker(code, exports);\n\n code = code.replace(\n new RegExp(`${marker}\\\\(\"([^\"]+)\"\\\\)`, 'g'),\n (_x, ref) => {\n let assetFileName = this.getFileName(ref);\n let relativeName =\n './' + relative(dirname(chunk.fileName), assetFileName);\n return getName(relativeName) ?? '';\n }\n );\n return imports() + code;\n },\n };\n}\n\nfunction nameTracker(code: string, exports: undefined | 'default' | '*') {\n let counter = 0;\n let assets = new Map<string, string | undefined>();\n\n function getName(assetName: string): string | undefined {\n if (assets.has(assetName)) {\n return assets.get(assetName)!;\n }\n if (!exports) {\n assets.set(assetName, undefined);\n return undefined;\n }\n while (true) {\n let candidate = `_asset_${counter++}_`;\n if (!code.includes(candidate)) {\n assets.set(assetName, candidate);\n return candidate;\n }\n }\n }\n\n function imports() {\n return (\n [...assets]\n .map(([assetName, importedName]) => {\n if (importedName) {\n return `import ${importedName} from \"${assetName}\"`;\n } else {\n return `import \"${assetName}\"`;\n }\n })\n .join('\\n') + '\\n'\n );\n }\n\n return { getName, imports };\n}\n"]}
|