@embroider/addon-dev 5.0.1-unstable.c2dff54 → 5.0.1-unstable.c51ca2b
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/README.md +20 -0
- package/package.json +4 -5
- package/src/rollup-gjs-plugin.js +1 -3
- package/src/rollup-gjs-plugin.js.map +1 -1
- package/src/rollup-hbs-plugin.js +62 -51
- package/src/rollup-hbs-plugin.js.map +1 -1
- package/src/rollup-incremental-plugin.d.ts +2 -0
- package/src/rollup-incremental-plugin.js +76 -0
- package/src/rollup-incremental-plugin.js.map +1 -0
- package/src/rollup-keep-assets.d.ts +2 -1
- package/src/rollup-keep-assets.js +64 -29
- package/src/rollup-keep-assets.js.map +1 -1
- package/src/rollup-public-entrypoints.js.map +1 -1
- package/src/rollup.d.ts +2 -3
- package/src/rollup.js +8 -6
- package/src/rollup.js.map +1 -1
package/README.md
CHANGED
|
@@ -22,6 +22,26 @@ For a guide on porting a V1 addon to V2, see https://github.com/embroider-build/
|
|
|
22
22
|
|
|
23
23
|
A rollup plugin to expose a folder of assets. `path` is a required to define which folder to expose. `options.include` is a glob pattern passed to `walkSync.include` to pick files. `options.exlude` is a glob pattern passed to `walkSync.ignore` to exclude files. `options.namespace` is the namespace to expose files, defaults to the package name + the path that you provided e.g. if you call `addon.publicAssets('public')` in a v2 addon named `super-addon` then your namespace will default to `super-addon/public`.
|
|
24
24
|
|
|
25
|
+
### addon.keepAssets(patterns: string[], exports?: 'default' | '*')
|
|
26
|
+
|
|
27
|
+
A rollup plugin to preserve imports of non-Javascript assets unchanged in your published package. For example, the v2-addon-blueprint uses:
|
|
28
|
+
|
|
29
|
+
```js
|
|
30
|
+
addon.keepAssets(['**/*.css'])
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
so that the line `import "./my.css"` in your addon will be preserved and the corresponding CSS file will get included at the right path.
|
|
34
|
+
|
|
35
|
+
`keepAssets` is intended to compose correctly with other plugins that synthesize CSS imports, like `glimmer-scoped-css`. It will capture their output and produce real CSS files in your published package.
|
|
36
|
+
|
|
37
|
+
The `exports` option defaults to `undefined` which means the assets are used for side-effect only and don't export any values. This is the supported way to use CSS in v2 addons. But you can also preserve assets that present themselves as having default exports with the value `"default"` or arbitrary named exports with the value `"*"`. For example:
|
|
38
|
+
|
|
39
|
+
```js
|
|
40
|
+
addon.keepAssets(["**/*.png"], "default")
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
lets you say `import imageURL from './my-image.png'`. Not that this pattern is **not** automatically supported in V2 addons and you would need to tell apps that consume your addon to handle it in a custom way.
|
|
44
|
+
|
|
25
45
|
## addon-dev command
|
|
26
46
|
|
|
27
47
|
The `addon-dev` command helps with common tasks in v2 addons.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@embroider/addon-dev",
|
|
3
|
-
"version": "5.0.1-unstable.
|
|
3
|
+
"version": "5.0.1-unstable.c51ca2b",
|
|
4
4
|
"description": "Utilities for addon authors",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -31,15 +31,14 @@
|
|
|
31
31
|
}
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@rollup/pluginutils": "^
|
|
35
|
-
"content-tag": "^2.0.
|
|
34
|
+
"@rollup/pluginutils": "^5.1.0",
|
|
35
|
+
"content-tag": "^2.0.2",
|
|
36
36
|
"fs-extra": "^10.0.0",
|
|
37
37
|
"minimatch": "^3.0.4",
|
|
38
38
|
"rollup-plugin-copy-assets": "^2.0.3",
|
|
39
|
-
"rollup-plugin-delete": "^2.0.0",
|
|
40
39
|
"walk-sync": "^3.0.0",
|
|
41
40
|
"yargs": "^17.0.1",
|
|
42
|
-
"@embroider/core": "^3.4.
|
|
41
|
+
"@embroider/core": "^3.4.16-unstable.c51ca2b"
|
|
43
42
|
},
|
|
44
43
|
"devDependencies": {
|
|
45
44
|
"@glimmer/syntax": "^0.84.2",
|
package/src/rollup-gjs-plugin.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.default = rollupGjsPlugin;
|
|
4
4
|
const pluginutils_1 = require("@rollup/pluginutils");
|
|
5
|
-
const fs_1 = require("fs");
|
|
6
5
|
const content_tag_1 = require("content-tag");
|
|
7
6
|
const PLUGIN_NAME = 'rollup-gjs-plugin';
|
|
8
7
|
const processor = new content_tag_1.Preprocessor();
|
|
@@ -10,11 +9,10 @@ const processor = new content_tag_1.Preprocessor();
|
|
|
10
9
|
function rollupGjsPlugin({ inline_source_map } = { inline_source_map: true }) {
|
|
11
10
|
return {
|
|
12
11
|
name: PLUGIN_NAME,
|
|
13
|
-
|
|
12
|
+
transform(input, id) {
|
|
14
13
|
if (!gjsFilter(id)) {
|
|
15
14
|
return null;
|
|
16
15
|
}
|
|
17
|
-
let input = (0, fs_1.readFileSync)(id, 'utf8');
|
|
18
16
|
let code = processor.process(input, {
|
|
19
17
|
filename: id,
|
|
20
18
|
inline_source_map,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rollup-gjs-plugin.js","sourceRoot":"","sources":["rollup-gjs-plugin.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"rollup-gjs-plugin.js","sourceRoot":"","sources":["rollup-gjs-plugin.ts"],"names":[],"mappings":";;AASA,kCAmBC;AA5BD,qDAAmD;AAEnD,6CAA2C;AAE3C,MAAM,WAAW,GAAG,mBAAmB,CAAC;AAExC,MAAM,SAAS,GAAG,IAAI,0BAAY,EAAE,CAAC;AACrC,6CAA6C;AAE7C,SAAwB,eAAe,CACrC,EAAE,iBAAiB,EAAE,GAAG,EAAE,iBAAiB,EAAE,IAAI,EAAE;IAEnD,OAAO;QACL,IAAI,EAAE,WAAW;QAEjB,SAAS,CAAC,KAAa,EAAE,EAAU;YACjC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,EAAE,CAAC;gBACnB,OAAO,IAAI,CAAC;YACd,CAAC;YACD,IAAI,IAAI,GAAG,SAAS,CAAC,OAAO,CAAC,KAAK,EAAE;gBAClC,QAAQ,EAAE,EAAE;gBACZ,iBAAiB;aAClB,CAAC,CAAC;YACH,OAAO;gBACL,IAAI;aACL,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC;AAED,MAAM,SAAS,GAAG,IAAA,0BAAY,EAAC,cAAc,CAAC,CAAC","sourcesContent":["import { createFilter } from '@rollup/pluginutils';\nimport type { Plugin } from 'rollup';\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(\n { inline_source_map } = { inline_source_map: true }\n): Plugin {\n return {\n name: PLUGIN_NAME,\n\n transform(input: string, id: string) {\n if (!gjsFilter(id)) {\n return null;\n }\n let code = processor.process(input, {\n filename: id,\n inline_source_map,\n });\n return {\n code,\n };\n },\n };\n}\n\nconst gjsFilter = createFilter('**/*.g{j,t}s');\n"]}
|
package/src/rollup-hbs-plugin.js
CHANGED
|
@@ -5,43 +5,86 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.default = rollupHbsPlugin;
|
|
7
7
|
const pluginutils_1 = require("@rollup/pluginutils");
|
|
8
|
-
const fs_1 = require("fs");
|
|
9
|
-
const core_1 = require("@embroider/core");
|
|
10
8
|
const minimatch_1 = __importDefault(require("minimatch"));
|
|
9
|
+
const core_1 = require("@embroider/core");
|
|
10
|
+
const path_1 = require("path");
|
|
11
|
+
const hbsFilter = (0, pluginutils_1.createFilter)('**/*.hbs?([?]*)');
|
|
11
12
|
function rollupHbsPlugin({ excludeColocation, }) {
|
|
12
13
|
return {
|
|
13
14
|
name: 'rollup-hbs-plugin',
|
|
14
15
|
async resolveId(source, importer, options) {
|
|
16
|
+
var _a, _b;
|
|
17
|
+
if ((_b = (_a = options.custom) === null || _a === void 0 ? void 0 : _a.embroider) === null || _b === void 0 ? void 0 : _b.isExtensionSearch) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
15
20
|
let resolution = await this.resolve(source, importer, {
|
|
16
21
|
skipSelf: true,
|
|
17
|
-
...options,
|
|
18
22
|
});
|
|
19
|
-
if (resolution) {
|
|
20
|
-
|
|
23
|
+
if (!resolution && (0, path_1.extname)(source) === '') {
|
|
24
|
+
resolution = await this.resolve(source + '.hbs', importer, {
|
|
25
|
+
skipSelf: true,
|
|
26
|
+
});
|
|
21
27
|
}
|
|
22
|
-
|
|
23
|
-
|
|
28
|
+
if (!resolution) {
|
|
29
|
+
let hbsSource = (0, core_1.syntheticJStoHBS)(source);
|
|
30
|
+
if (hbsSource) {
|
|
31
|
+
resolution = await this.resolve(hbsSource, importer, {
|
|
32
|
+
skipSelf: true,
|
|
33
|
+
custom: {
|
|
34
|
+
embroider: {
|
|
35
|
+
isExtensionSearch: true,
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
if (!resolution) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (resolution && resolution.id.endsWith('.hbs')) {
|
|
45
|
+
let isExcluded = excludeColocation === null || excludeColocation === void 0 ? void 0 : excludeColocation.some((glob) => (0, minimatch_1.default)(resolution.id, glob));
|
|
46
|
+
if (isExcluded) {
|
|
47
|
+
return resolution;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
let syntheticId = (0, core_1.needsSyntheticComponentJS)(source, resolution.id);
|
|
51
|
+
if (syntheticId) {
|
|
52
|
+
this.addWatchFile(source);
|
|
53
|
+
return {
|
|
54
|
+
id: syntheticId,
|
|
55
|
+
meta: {
|
|
56
|
+
'rollup-hbs-plugin': {
|
|
57
|
+
type: 'template-only-component-js',
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
};
|
|
24
61
|
}
|
|
25
62
|
},
|
|
26
63
|
load(id) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
let meta = getMeta(this, id);
|
|
31
|
-
if (meta) {
|
|
32
|
-
if ((meta === null || meta === void 0 ? void 0 : meta.type) === 'template-js') {
|
|
33
|
-
const hbsFile = id.replace(/\.js$/, '.hbs');
|
|
34
|
-
return getHbsToJSCode(hbsFile);
|
|
35
|
-
}
|
|
64
|
+
var _a;
|
|
65
|
+
if (((_a = getMeta(this, id)) === null || _a === void 0 ? void 0 : _a.type) === 'template-only-component-js') {
|
|
66
|
+
this.addWatchFile(id);
|
|
36
67
|
return {
|
|
37
|
-
code:
|
|
68
|
+
code: (0, core_1.templateOnlyComponentSource)(),
|
|
38
69
|
};
|
|
39
70
|
}
|
|
40
71
|
},
|
|
72
|
+
transform(code, id) {
|
|
73
|
+
var _a;
|
|
74
|
+
let hbsFilename = id.replace(/\.\w{1,3}$/, '') + '.hbs';
|
|
75
|
+
if (hbsFilename !== id) {
|
|
76
|
+
this.addWatchFile(hbsFilename);
|
|
77
|
+
if (((_a = getMeta(this, id)) === null || _a === void 0 ? void 0 : _a.type) === 'template-only-component-js') {
|
|
78
|
+
this.addWatchFile(id);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (!hbsFilter(id)) {
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
return (0, core_1.hbsToJS)(code);
|
|
85
|
+
},
|
|
41
86
|
};
|
|
42
87
|
}
|
|
43
|
-
const templateOnlyComponent = `import templateOnly from '@ember/component/template-only';\n` +
|
|
44
|
-
`export default templateOnly();\n`;
|
|
45
88
|
function getMeta(context, id) {
|
|
46
89
|
var _a, _b;
|
|
47
90
|
const meta = (_b = (_a = context.getModuleInfo(id)) === null || _a === void 0 ? void 0 : _a.meta) === null || _b === void 0 ? void 0 : _b['rollup-hbs-plugin'];
|
|
@@ -52,36 +95,4 @@ function getMeta(context, id) {
|
|
|
52
95
|
return null;
|
|
53
96
|
}
|
|
54
97
|
}
|
|
55
|
-
function getHbsToJSCode(file) {
|
|
56
|
-
let input = (0, fs_1.readFileSync)(file, 'utf8');
|
|
57
|
-
let code = (0, core_1.hbsToJS)(input);
|
|
58
|
-
return {
|
|
59
|
-
code,
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
async function maybeSynthesizeComponentJS(context, source, importer, options, excludeColocation) {
|
|
63
|
-
let hbsFilename = (0, core_1.correspondingTemplate)(source);
|
|
64
|
-
let templateResolution = await context.resolve(hbsFilename, importer, {
|
|
65
|
-
skipSelf: true,
|
|
66
|
-
...options,
|
|
67
|
-
});
|
|
68
|
-
if (!templateResolution) {
|
|
69
|
-
return null;
|
|
70
|
-
}
|
|
71
|
-
let type = (excludeColocation === null || excludeColocation === void 0 ? void 0 : excludeColocation.some((glob) => (0, minimatch_1.default)(hbsFilename, glob)))
|
|
72
|
-
? 'template-js'
|
|
73
|
-
: 'template-only-component-js';
|
|
74
|
-
// we're trying to resolve a JS module but only the corresponding HBS
|
|
75
|
-
// file exists. Synthesize the JS. The meta states if the hbs corresponds
|
|
76
|
-
// to a template-only component or a simple template like a route template.
|
|
77
|
-
return {
|
|
78
|
-
id: templateResolution.id.replace(/\.hbs$/, '.js'),
|
|
79
|
-
meta: {
|
|
80
|
-
'rollup-hbs-plugin': {
|
|
81
|
-
type,
|
|
82
|
-
},
|
|
83
|
-
},
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
const hbsFilter = (0, pluginutils_1.createFilter)('**/*.hbs');
|
|
87
98
|
//# sourceMappingURL=rollup-hbs-plugin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rollup-hbs-plugin.js","sourceRoot":"","sources":["rollup-hbs-plugin.ts"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"rollup-hbs-plugin.js","sourceRoot":"","sources":["rollup-hbs-plugin.ts"],"names":[],"mappings":";;;;;AAaA,kCAsFC;AA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ACH,CAAC;YACD,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,EAAE,CAAC;gBACnB,OAAO,IAAI,CAAC;YACd,CAAC;YACD,OAAO,IAAA,cAAO,EAAC,IAAI,CAAC,CAAC;QACvB,CAAC;KACF,CAAC;AACJ,CAAC;AAMD,SAAS,OAAO,CAAC,OAAsB,EAAE,EAAU;;IACjD,MAAM,IAAI,GAAG,MAAA,MAAA,OAAO,CAAC,aAAa,CAAC,EAAE,CAAC,0CAAE,IAAI,0CAAG,mBAAmB,CAAC,CAAC;IACpE,IAAI,IAAI,EAAE,CAAC;QACT,OAAO,IAAY,CAAC;IACtB,CAAC;SAAM,CAAC;QACN,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC","sourcesContent":["import type { Plugin, PluginContext } from 'rollup';\nimport { createFilter } from '@rollup/pluginutils';\nimport minimatch from 'minimatch';\nimport {\n hbsToJS,\n templateOnlyComponentSource,\n needsSyntheticComponentJS,\n syntheticJStoHBS,\n} from '@embroider/core';\nimport { extname } from 'path';\n\nconst hbsFilter = createFilter('**/*.hbs?([?]*)');\n\nexport default function rollupHbsPlugin({\n excludeColocation,\n}: {\n excludeColocation?: string[];\n}): Plugin {\n return {\n name: 'rollup-hbs-plugin',\n async resolveId(source: string, importer: string | undefined, options) {\n if (options.custom?.embroider?.isExtensionSearch) {\n return null;\n }\n\n let resolution = await this.resolve(source, importer, {\n skipSelf: true,\n });\n\n if (!resolution && extname(source) === '') {\n resolution = await this.resolve(source + '.hbs', importer, {\n skipSelf: true,\n });\n }\n\n if (!resolution) {\n let hbsSource = syntheticJStoHBS(source);\n if (hbsSource) {\n resolution = await this.resolve(hbsSource, importer, {\n skipSelf: true,\n custom: {\n embroider: {\n isExtensionSearch: true,\n },\n },\n });\n }\n\n if (!resolution) {\n return null;\n }\n }\n\n if (resolution && resolution.id.endsWith('.hbs')) {\n let isExcluded = excludeColocation?.some((glob) =>\n minimatch(resolution!.id, glob)\n );\n if (isExcluded) {\n return resolution;\n }\n }\n\n let syntheticId = needsSyntheticComponentJS(source, resolution.id);\n if (syntheticId) {\n this.addWatchFile(source);\n return {\n id: syntheticId,\n meta: {\n 'rollup-hbs-plugin': {\n type: 'template-only-component-js',\n },\n },\n };\n }\n },\n\n load(id: string) {\n if (getMeta(this, id)?.type === 'template-only-component-js') {\n this.addWatchFile(id);\n return {\n code: templateOnlyComponentSource(),\n };\n }\n },\n\n transform(code: string, id: string) {\n let hbsFilename = id.replace(/\\.\\w{1,3}$/, '') + '.hbs';\n if (hbsFilename !== id) {\n this.addWatchFile(hbsFilename);\n if (getMeta(this, id)?.type === 'template-only-component-js') {\n this.addWatchFile(id);\n }\n }\n if (!hbsFilter(id)) {\n return null;\n }\n return hbsToJS(code);\n },\n };\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"]}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.default = incremental;
|
|
7
|
+
const walk_sync_1 = __importDefault(require("walk-sync"));
|
|
8
|
+
const fs_1 = require("fs");
|
|
9
|
+
const path_1 = require("path");
|
|
10
|
+
const fs_extra_1 = require("fs-extra");
|
|
11
|
+
function incremental() {
|
|
12
|
+
const generatedAssets = new Map();
|
|
13
|
+
const generatedFiles = new Set();
|
|
14
|
+
function isEqual(v1, v2) {
|
|
15
|
+
if (typeof v1 === 'string' && typeof v2 === 'string') {
|
|
16
|
+
return v1 === v2;
|
|
17
|
+
}
|
|
18
|
+
if (Buffer.isBuffer(v1) && Buffer.isBuffer(v2)) {
|
|
19
|
+
return v1.equals(v2);
|
|
20
|
+
}
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
let firstTime = true;
|
|
24
|
+
function initGeneratedFiles(outDir) {
|
|
25
|
+
if ((0, fs_extra_1.existsSync)(outDir)) {
|
|
26
|
+
const files = (0, walk_sync_1.default)(outDir, {
|
|
27
|
+
globs: ['*/**'],
|
|
28
|
+
directories: false,
|
|
29
|
+
});
|
|
30
|
+
for (const file of files) {
|
|
31
|
+
generatedFiles.add(file);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function deleteRemovedFiles(bundle, outDir) {
|
|
36
|
+
for (const file of generatedFiles) {
|
|
37
|
+
if (!bundle[file]) {
|
|
38
|
+
generatedAssets.delete(file);
|
|
39
|
+
(0, fs_1.rmSync)((0, path_1.join)(outDir, file));
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
generatedFiles.clear();
|
|
43
|
+
for (const file of Object.keys(bundle)) {
|
|
44
|
+
generatedFiles.add(file);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function syncFiles(bundle) {
|
|
48
|
+
for (const checkKey of Object.keys(bundle)) {
|
|
49
|
+
if (bundle[checkKey]) {
|
|
50
|
+
let module = bundle[checkKey];
|
|
51
|
+
let code = module.source || module.code;
|
|
52
|
+
if (generatedAssets.has(checkKey) &&
|
|
53
|
+
isEqual(code, generatedAssets.get(checkKey))) {
|
|
54
|
+
delete bundle[checkKey];
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
generatedAssets.set(checkKey, code);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return {
|
|
63
|
+
name: 'incremental',
|
|
64
|
+
generateBundle(options, bundle) {
|
|
65
|
+
if (firstTime) {
|
|
66
|
+
firstTime = false;
|
|
67
|
+
initGeneratedFiles(options.dir);
|
|
68
|
+
}
|
|
69
|
+
if ((0, fs_extra_1.existsSync)(options.dir)) {
|
|
70
|
+
deleteRemovedFiles(bundle, options.dir);
|
|
71
|
+
}
|
|
72
|
+
syncFiles(bundle);
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=rollup-incremental-plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rollup-incremental-plugin.js","sourceRoot":"","sources":["rollup-incremental-plugin.ts"],"names":[],"mappings":";;;;;AAMA,8BAwEC;AA9ED,0DAAiC;AACjC,2BAA4B;AAC5B,+BAA4B;AAE5B,uCAAsC;AAEtC,SAAwB,WAAW;IACjC,MAAM,eAAe,GAAG,IAAI,GAAG,EAAE,CAAC;IAClC,MAAM,cAAc,GAAG,IAAI,GAAG,EAAU,CAAC;IAEzC,SAAS,OAAO,CAAC,EAAuB,EAAE,EAAuB;QAC/D,IAAI,OAAO,EAAE,KAAK,QAAQ,IAAI,OAAO,EAAE,KAAK,QAAQ,EAAE,CAAC;YACrD,OAAO,EAAE,KAAK,EAAE,CAAC;QACnB,CAAC;QACD,IAAI,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,IAAI,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC;YAC/C,OAAO,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QACvB,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,SAAS,GAAG,IAAI,CAAC;IAErB,SAAS,kBAAkB,CAAC,MAAc;QACxC,IAAI,IAAA,qBAAU,EAAC,MAAM,CAAC,EAAE,CAAC;YACvB,MAAM,KAAK,GAAG,IAAA,mBAAQ,EAAC,MAAM,EAAE;gBAC7B,KAAK,EAAE,CAAC,MAAM,CAAC;gBACf,WAAW,EAAE,KAAK;aACnB,CAAC,CAAC;YACH,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;gBACzB,cAAc,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YAC3B,CAAC;QACH,CAAC;I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AC;gBAClB,kBAAkB,CAAC,OAAO,CAAC,GAAI,CAAC,CAAC;YACnC,CAAC;YACD,IAAI,IAAA,qBAAU,EAAC,OAAO,CAAC,GAAI,CAAC,EAAE,CAAC;gBAC7B,kBAAkB,CAAC,MAAM,EAAE,OAAO,CAAC,GAAI,CAAC,CAAC;YAC3C,CAAC;YAED,SAAS,CAAC,MAAM,CAAC,CAAC;QACpB,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import walkSync from 'walk-sync';\nimport { rmSync } from 'fs';\nimport { join } from 'path';\nimport type { Plugin } from 'rollup';\nimport { existsSync } from 'fs-extra';\n\nexport default function incremental(): Plugin {\n const generatedAssets = new Map();\n const generatedFiles = new Set<string>();\n\n function isEqual(v1: string | Uint8Array, v2: string | Uint8Array): boolean {\n if (typeof v1 === 'string' && typeof v2 === 'string') {\n return v1 === v2;\n }\n if (Buffer.isBuffer(v1) && Buffer.isBuffer(v2)) {\n return v1.equals(v2);\n }\n return false;\n }\n\n let firstTime = true;\n\n function initGeneratedFiles(outDir: string) {\n if (existsSync(outDir)) {\n const files = walkSync(outDir, {\n globs: ['*/**'],\n directories: false,\n });\n for (const file of files) {\n generatedFiles.add(file);\n }\n }\n }\n\n function deleteRemovedFiles(bundle: Record<string, any>, outDir: string) {\n for (const file of generatedFiles) {\n if (!bundle[file]) {\n generatedAssets.delete(file);\n rmSync(join(outDir, file));\n }\n }\n generatedFiles.clear();\n for (const file of Object.keys(bundle)) {\n generatedFiles.add(file);\n }\n }\n\n function syncFiles(bundle: Record<string, any>) {\n for (const checkKey of Object.keys(bundle)) {\n if (bundle[checkKey]) {\n let module = bundle[checkKey] as any;\n let code = module.source || module.code;\n if (\n generatedAssets.has(checkKey) &&\n isEqual(code, generatedAssets.get(checkKey))\n ) {\n delete bundle[checkKey];\n } else {\n generatedAssets.set(checkKey, code);\n }\n }\n }\n }\n\n return {\n name: 'incremental',\n generateBundle(options, bundle) {\n if (firstTime) {\n firstTime = false;\n initGeneratedFiles(options.dir!);\n }\n if (existsSync(options.dir!)) {\n deleteRemovedFiles(bundle, options.dir!);\n }\n\n syncFiles(bundle);\n },\n };\n}\n"]}
|
|
@@ -4,42 +4,77 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.default = keepAssets;
|
|
7
|
-
const walk_sync_1 = __importDefault(require("walk-sync"));
|
|
8
|
-
const fs_1 = require("fs");
|
|
9
|
-
const path_1 = require("path");
|
|
10
7
|
const minimatch_1 = __importDefault(require("minimatch"));
|
|
11
|
-
|
|
8
|
+
const path_1 = require("path");
|
|
9
|
+
// randomly chosen, we're just looking to have high-entropy identifiers that
|
|
10
|
+
// won't collide with anyting else in the source
|
|
11
|
+
let counter = 11559;
|
|
12
|
+
function keepAssets({ from, include, exports, }) {
|
|
13
|
+
const marker = `__copy_asset_marker_${counter++}__`;
|
|
12
14
|
return {
|
|
13
15
|
name: 'copy-assets',
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const resolution = await this.resolve(source, importer, {
|
|
18
|
-
skipSelf: true,
|
|
19
|
-
...options,
|
|
20
|
-
});
|
|
21
|
-
if (resolution &&
|
|
22
|
-
importer &&
|
|
23
|
-
include.some((pattern) => (0, minimatch_1.default)(resolution.id, pattern))) {
|
|
24
|
-
return { id: (0, path_1.resolve)((0, path_1.dirname)(importer), source), external: 'relative' };
|
|
25
|
-
}
|
|
26
|
-
return resolution;
|
|
27
|
-
},
|
|
28
|
-
// the assets go into the output directory in the same relative locations as
|
|
29
|
-
// in the input directory
|
|
30
|
-
async generateBundle() {
|
|
31
|
-
for (let name of (0, walk_sync_1.default)(from, {
|
|
32
|
-
globs: include,
|
|
33
|
-
directories: false,
|
|
34
|
-
})) {
|
|
35
|
-
this.addWatchFile((0, path_1.join)(from, name));
|
|
36
|
-
this.emitFile({
|
|
16
|
+
transform(code, id) {
|
|
17
|
+
if (include.some((pattern) => (0, minimatch_1.default)(id, pattern))) {
|
|
18
|
+
let ref = this.emitFile({
|
|
37
19
|
type: 'asset',
|
|
38
|
-
fileName:
|
|
39
|
-
source:
|
|
20
|
+
fileName: (0, path_1.relative)(from, id),
|
|
21
|
+
source: code,
|
|
40
22
|
});
|
|
23
|
+
if (exports === '*') {
|
|
24
|
+
return `export * from ${marker}("${ref}")`;
|
|
25
|
+
}
|
|
26
|
+
else if (exports === 'default') {
|
|
27
|
+
return `export default ${marker}("${ref}")`;
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
// side-effect only
|
|
31
|
+
return `${marker}("${ref}")`;
|
|
32
|
+
}
|
|
41
33
|
}
|
|
42
34
|
},
|
|
35
|
+
renderChunk(code, chunk) {
|
|
36
|
+
const { getName, imports } = nameTracker(code, exports);
|
|
37
|
+
code = code.replace(new RegExp(`${marker}\\("([^"]+)"\\)`, 'g'), (_x, ref) => {
|
|
38
|
+
var _a;
|
|
39
|
+
let assetFileName = this.getFileName(ref);
|
|
40
|
+
let relativeName = './' + (0, path_1.relative)((0, path_1.dirname)(chunk.fileName), assetFileName);
|
|
41
|
+
return (_a = getName(relativeName)) !== null && _a !== void 0 ? _a : '';
|
|
42
|
+
});
|
|
43
|
+
return imports() + code;
|
|
44
|
+
},
|
|
43
45
|
};
|
|
44
46
|
}
|
|
47
|
+
function nameTracker(code, exports) {
|
|
48
|
+
let counter = 0;
|
|
49
|
+
let assets = new Map();
|
|
50
|
+
function getName(assetName) {
|
|
51
|
+
if (assets.has(assetName)) {
|
|
52
|
+
return assets.get(assetName);
|
|
53
|
+
}
|
|
54
|
+
if (!exports) {
|
|
55
|
+
assets.set(assetName, undefined);
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
while (true) {
|
|
59
|
+
let candidate = `_asset_${counter++}_`;
|
|
60
|
+
if (!code.includes(candidate)) {
|
|
61
|
+
assets.set(assetName, candidate);
|
|
62
|
+
return candidate;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
function imports() {
|
|
67
|
+
return ([...assets]
|
|
68
|
+
.map(([assetName, importedName]) => {
|
|
69
|
+
if (importedName) {
|
|
70
|
+
return `import ${importedName} from "${assetName}"`;
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
return `import "${assetName}"`;
|
|
74
|
+
}
|
|
75
|
+
})
|
|
76
|
+
.join('\n') + '\n');
|
|
77
|
+
}
|
|
78
|
+
return { getName, imports };
|
|
79
|
+
}
|
|
45
80
|
//# sourceMappingURL=rollup-keep-assets.js.map
|
|
@@ -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":";;;;;AAQA,6BA8CC;AArDD,0DAAkC;AAClC,+BAAyC;AAEzC,4EAA4E;AAC5E,gDAAgD;AAChD,IAAI,OAAO,GAAG,KAAK,CAAC;AAEpB,SAAwB,UAAU,CAAC,EACjC,IAAI,EACJ,OAAO,EACP,OAAO,GAKR;IACC,MAAM,MAAM,GAAG,uBAAuB,OAAO,EAAE,IAAI,CAAC;IAEpD,OAAO;QACL,IAAI,EAAE,aAAa;QAEnB,SAAS,CAAC,IAAY,EAAE,EAAU;YAChC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,IAAA,mBAAS,EAAC,EAAE,EAAE,OAAO,CAAC,CAAC,EAAE,CAAC;gBACtD,IAAI,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC;oBACtB,IAAI,EAAE,OAAO;oBACb,QAAQ,EAAE,IAAA,eAAQ,EAAC,IAAI,EAAE,EAAE,CAAC;oBAC5B,MAAM,EAAE,IAAI;iBACb,CAAC,CAAC;gBACH,IAAI,OAAO,KAAK,GAAG,EAAE,CAAC;oBACpB,OAAO,iBA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,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';\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 = `__copy_asset_marker_${counter++}__`;\n\n return {\n name: 'copy-assets',\n\n transform(code: string, id: string) {\n if (include.some((pattern) => minimatch(id, pattern))) {\n let ref = this.emitFile({\n type: 'asset',\n fileName: relative(from, id),\n source: code,\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"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rollup-public-entrypoints.js","sourceRoot":"","sources":["rollup-public-entrypoints.ts"],"names":[],"mappings":";;;;;AAUA,oCAkEC;AA5ED,0DAAiC;AACjC,gDAAwB;AACxB,0DAAkC;AAIlC,SAAS,gBAAgB,CAAC,QAAgB;IACxC,OAAO,QAAQ,CAAC,OAAO,CAAC,iCAAiC,EAAE,KAAK,CAAC,CAAC;AACpE,CAAC;AAED,SAAwB,iBAAiB,CAAC,IAIzC;IACC,OAAO;QACL,IAAI,EAAE,eAAe;
|
|
1
|
+
{"version":3,"file":"rollup-public-entrypoints.js","sourceRoot":"","sources":["rollup-public-entrypoints.ts"],"names":[],"mappings":";;;;;AAUA,oCAkEC;AA5ED,0DAAiC;AACjC,gDAAwB;AACxB,0DAAkC;AAIlC,SAA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AK,CAAC,CAAC;IAEnE,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import walkSync from 'walk-sync';\nimport path from 'path';\nimport minimatch from 'minimatch';\n\nimport type { Plugin } from 'rollup';\n\nfunction normalizeFileExt(fileName: string) {\n return fileName.replace(/(?<!\\.d)\\.ts|\\.hbs|\\.gts|\\.gjs$/, '.js');\n}\n\nexport default function publicEntrypoints(args: {\n srcDir: string;\n include: string[];\n exclude?: string[];\n}): Plugin {\n return {\n name: 'addon-modules',\n\n async buildStart() {\n let matches = walkSync(args.srcDir, {\n globs: [...args.include, '**/*.hbs', '**/*.ts', '**/*.gts', '**/*.gjs'],\n ignore: args.exclude,\n });\n\n for (let name of matches) {\n this.addWatchFile(path.join(args.srcDir, name));\n // the matched file, but with the extension swapped with .js\n let normalizedName = normalizeFileExt(name);\n\n // anything that doesn't match the users patterns, and wasn't a template-only\n // component needs to be emitted \"as-is\" so that other plugins may handle it.\n let isTO = isTemplateOnly(matches, name);\n\n let isHbs = path.extname(name) === '.hbs';\n\n // hbs for-colocated components is handled by the rollup-hbs-plugin\n // hbs for template-only components is handled in the isTO block\n if (isHbs && !isTO) {\n continue;\n }\n\n // these chunks matched are **/*.hbs glob and are\n // guaranteed to not have any corresponding file as a co-located component would have.\n if (isTO) {\n this.emitFile({\n type: 'chunk',\n id: path.join(args.srcDir, normalizedName),\n fileName: normalizedName,\n });\n\n continue;\n }\n\n // anything that matches one of the user's patterns is definitely emitted\n let isUserDefined = args.include.some((pattern) =>\n minimatch(name, pattern)\n );\n\n // additionally, we want to emit chunks where the pattern matches the supported\n // file extensions above (TS, GTS, etc) as if they were already the built JS.\n let wouldMatchIfBuilt = args.include.some((pattern) =>\n minimatch(normalizedName, pattern)\n );\n\n if (isUserDefined || wouldMatchIfBuilt) {\n this.emitFile({\n type: 'chunk',\n id: path.join(args.srcDir, name),\n fileName: normalizedName,\n });\n\n continue;\n }\n }\n },\n };\n}\n\nfunction isTemplateOnly(matches: string[], filePath: string) {\n let isHbs = path.extname(filePath) === '.hbs';\n\n if (!isHbs) return false;\n\n let correspondingFileGlob = path.join(\n path.dirname(filePath),\n path.basename(filePath).replace(/hbs$/, '*')\n );\n\n let relatedFiles = matches.filter((match) =>\n minimatch(match, correspondingFileGlob)\n );\n let isTO = relatedFiles.filter((x) => x !== filePath).length === 0;\n\n return isTO;\n}\n"]}
|
package/src/rollup.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { Options as DelOptions } from 'rollup-plugin-delete';
|
|
2
1
|
import { type PublicAssetsOptions } from './rollup-public-assets';
|
|
3
2
|
import type { Plugin } from 'rollup';
|
|
4
3
|
export declare class Addon {
|
|
@@ -19,8 +18,8 @@ export declare class Addon {
|
|
|
19
18
|
gjs(options?: {
|
|
20
19
|
inline_source_map: boolean;
|
|
21
20
|
}): Plugin<any>;
|
|
22
|
-
clean(
|
|
23
|
-
keepAssets(patterns: string[]): Plugin<any>;
|
|
21
|
+
clean(): Plugin<any>;
|
|
22
|
+
keepAssets(patterns: string[], exports?: undefined | 'default' | '*'): Plugin<any>;
|
|
24
23
|
output(): {
|
|
25
24
|
dir: string;
|
|
26
25
|
entryFileNames: string;
|
package/src/rollup.js
CHANGED
|
@@ -20,10 +20,10 @@ const rollup_hbs_plugin_1 = __importDefault(require("./rollup-hbs-plugin"));
|
|
|
20
20
|
const rollup_gjs_plugin_1 = __importDefault(require("./rollup-gjs-plugin"));
|
|
21
21
|
const rollup_public_entrypoints_1 = __importDefault(require("./rollup-public-entrypoints"));
|
|
22
22
|
const rollup_app_reexports_1 = __importDefault(require("./rollup-app-reexports"));
|
|
23
|
-
const rollup_plugin_delete_1 = __importDefault(require("rollup-plugin-delete"));
|
|
24
23
|
const rollup_keep_assets_1 = __importDefault(require("./rollup-keep-assets"));
|
|
25
24
|
const rollup_addon_dependencies_1 = __importDefault(require("./rollup-addon-dependencies"));
|
|
26
25
|
const rollup_public_assets_1 = __importDefault(require("./rollup-public-assets"));
|
|
26
|
+
const rollup_incremental_plugin_1 = __importDefault(require("./rollup-incremental-plugin"));
|
|
27
27
|
class Addon {
|
|
28
28
|
constructor(params = {}) {
|
|
29
29
|
var _a, _b;
|
|
@@ -64,19 +64,21 @@ class Addon {
|
|
|
64
64
|
gjs(options) {
|
|
65
65
|
return (0, rollup_gjs_plugin_1.default)(options);
|
|
66
66
|
}
|
|
67
|
-
//
|
|
68
|
-
//
|
|
69
|
-
|
|
70
|
-
|
|
67
|
+
// this does incremental updates to the dist files and also deletes files that are not part of the generated bundle
|
|
68
|
+
// rollup already supports incremental transforms of files,
|
|
69
|
+
// this extends it to the dist files
|
|
70
|
+
clean() {
|
|
71
|
+
return (0, rollup_incremental_plugin_1.default)();
|
|
71
72
|
}
|
|
72
73
|
// V2 Addons are allowed to contain imports of .css files. This tells rollup
|
|
73
74
|
// to leave those imports alone and to make sure the corresponding .css files
|
|
74
75
|
// are kept in the same relative locations in the destDir as they were in the
|
|
75
76
|
// srcDir.
|
|
76
|
-
keepAssets(patterns) {
|
|
77
|
+
keepAssets(patterns, exports) {
|
|
77
78
|
return (0, rollup_keep_assets_1.default)({
|
|
78
79
|
from: __classPrivateFieldGet(this, _Addon_srcDir, "f"),
|
|
79
80
|
include: patterns,
|
|
81
|
+
exports: exports,
|
|
80
82
|
});
|
|
81
83
|
}
|
|
82
84
|
// This is the default `output` configuration you should pass to rollup. We're
|
package/src/rollup.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rollup.js","sourceRoot":"","sources":["rollup.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,4EAAqD;AACrD,4EAAqD;AACrD,4FAA2E;AAC3E,kFAAiE;
|
|
1
|
+
{"version":3,"file":"rollup.js","sourceRoot":"","sources":["rollup.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,4EAAqD;AACrD,4EAAqD;AACrD,4FAA2E;AAC3E,kFAAiE;AACjE,8EAA6D;AAC7D,4FAAsE;AACtE,kFA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;IAC7E,6EAA6E;IAC7E,UAAU;IACV,UAAU,CAAC,QAAkB,EAAE,OAAqC;QAClE,OAAO,IAAA,4BAAU,EAAC;YAChB,IAAI,EAAE,uBAAA,IAAI,qBAAQ;YAClB,OAAO,EAAE,QAAQ;YACjB,OAAO,EAAE,OAAO;SACjB,CAAC,CAAC;IACL,CAAC;IAED,8EAA8E;IAC9E,2EAA2E;IAC3E,4EAA4E;IAC5E,UAAU;IACV,EAAE;IACF,wFAAwF;IACxF,qDAAqD;IACrD,qFAAqF;IACrF,sBAAsB;IACtB,MAAM;QACJ,OAAO;YACL,GAAG,EAAE,uBAAA,IAAI,sBAAS;YAClB,cAAc,EAAE,QAAQ;YACxB,wBAAwB,EAAE,CAAC;YAC3B,MAAM,EAAE,IAAI;YACZ,sBAAsB,EAAE,KAAK;YAC7B,SAAS,EAAE,IAAI;SAChB,CAAC;IACJ,CAAC;IAED,YAAY;QACV,OAAO,IAAA,mCAAY,GAAE,CAAC;IACxB,CAAC;IAED,YAAY,CAAC,IAAY,EAAE,IAA0B;QACnD,OAAO,IAAA,8BAAY,EAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAClC,CAAC;CACF;AAlGD,sBAkGC","sourcesContent":["import { default as hbs } from './rollup-hbs-plugin';\nimport { default as gjs } from './rollup-gjs-plugin';\nimport { default as publicEntrypoints } from './rollup-public-entrypoints';\nimport { default as appReexports } from './rollup-app-reexports';\nimport { default as keepAssets } from './rollup-keep-assets';\nimport { default as dependencies } from './rollup-addon-dependencies';\nimport {\n default as publicAssets,\n type PublicAssetsOptions,\n} from './rollup-public-assets';\nimport { default as clean } from './rollup-incremental-plugin';\nimport type { Plugin } from 'rollup';\n\nexport class Addon {\n #srcDir: string;\n #destDir: string;\n\n constructor(params: { srcDir?: string; destDir?: string } = {}) {\n this.#srcDir = params.srcDir ?? 'src';\n this.#destDir = params.destDir ?? 'dist';\n }\n\n // Given a list of globs describing modules in your srcDir, this generates\n // corresponding appTree modules that contain reexports, and updates your\n // package.json metadata to list them all.\n appReexports(\n patterns: string[],\n opts: {\n mapFilename?: (fileName: string) => string;\n exports?: (filename: string) => string[] | string | undefined;\n exclude?: string[];\n } = {}\n ): Plugin {\n return appReexports({\n from: this.#srcDir,\n to: this.#destDir,\n include: patterns,\n mapFilename: opts.mapFilename,\n exports: opts.exports,\n exclude: opts.exclude,\n });\n }\n\n // This configures rollup to emit public entrypoints for each module in your\n // srcDir that matches one of the given globs. Typical addons will want to\n // match patterns like \"components/**/*.js\", \"index.js\", and \"test-support.js\".\n publicEntrypoints(patterns: string[], opts: { exclude?: string[] } = {}) {\n return publicEntrypoints({\n srcDir: this.#srcDir,\n include: patterns,\n exclude: opts.exclude,\n });\n }\n\n // This wraps standalone .hbs files as Javascript files using inline\n // templates. This means special resolving rules for .hbs files aren't\n // required for javascript tooling to understand your package.\n hbs(options = {}) {\n return hbs(options);\n }\n\n gjs(options?: { inline_source_map: boolean }) {\n return gjs(options);\n }\n\n // this does incremental updates to the dist files and also deletes files that are not part of the generated bundle\n // rollup already supports incremental transforms of files,\n // this extends it to the dist files\n clean() {\n return clean();\n }\n\n // V2 Addons are allowed to contain imports of .css files. This tells rollup\n // to leave those imports alone and to make sure the corresponding .css files\n // are kept in the same relative locations in the destDir as they were in the\n // srcDir.\n keepAssets(patterns: string[], exports?: undefined | 'default' | '*') {\n return keepAssets({\n from: this.#srcDir,\n include: patterns,\n exports: exports,\n });\n }\n\n // This is the default `output` configuration you should pass to rollup. We're\n // emitting ES modules, in your `destDir`, and their filenames are equal to\n // their bundle names (the bundle names get generated by `publicEntrypoints`\n // above).\n //\n // hoistTransitiveImports is disabled because the purpose of hoisting transitive imports\n // is to improve performance of apps loading modules.\n // Since v2 addons do not know exactly how they'll be used, this performance decision\n // is left up to apps.\n output() {\n return {\n dir: this.#destDir,\n entryFileNames: '[name]',\n experimentalMinChunkSize: 0,\n format: 'es',\n hoistTransitiveImports: false,\n sourcemap: true,\n };\n }\n\n dependencies() {\n return dependencies();\n }\n\n publicAssets(path: string, opts?: PublicAssetsOptions) {\n return publicAssets(path, opts);\n }\n}\n"]}
|