@embroider/core 3.4.10-unstable.706d56f → 3.4.10-unstable.93b39c4
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 +6 -5
- package/src/app-files.d.ts +1 -1
- package/src/app-files.js +9 -2
- package/src/app-files.js.map +1 -1
- package/src/index.d.ts +0 -1
- package/src/index.js.map +1 -1
- package/src/module-resolver.d.ts +6 -0
- package/src/module-resolver.js +67 -2
- package/src/module-resolver.js.map +1 -1
- package/src/virtual-content.js +15 -0
- package/src/virtual-content.js.map +1 -1
- package/src/virtual-entrypoint.d.ts +19 -0
- package/src/virtual-entrypoint.js +303 -0
- package/src/virtual-entrypoint.js.map +1 -0
- package/src/virtual-route-entrypoint.d.ts +15 -0
- package/src/virtual-route-entrypoint.js +102 -0
- package/src/virtual-route-entrypoint.js.map +1 -0
- package/src/virtual-test-entrypoint.d.ts +10 -0
- package/src/virtual-test-entrypoint.js +67 -0
- package/src/virtual-test-entrypoint.js.map +1 -0
- package/src/virtual-vendor-styles.js +29 -18
- package/src/virtual-vendor-styles.js.map +1 -1
- package/src/asset.d.ts +0 -35
- package/src/asset.js +0 -3
- package/src/asset.js.map +0 -1
- package/src/ember-html.d.ts +0 -45
- package/src/ember-html.js +0 -110
- package/src/ember-html.js.map +0 -1
@@ -0,0 +1,67 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.renderTestEntrypoint = exports.decodeTestEntrypoint = void 0;
|
4
|
+
const app_files_1 = require("./app-files");
|
5
|
+
const js_handlebars_1 = require("./js-handlebars");
|
6
|
+
const shared_internals_1 = require("@embroider/shared-internals");
|
7
|
+
const virtual_entrypoint_1 = require("./virtual-entrypoint");
|
8
|
+
const entrypointPattern = /(?<filename>.*)[\\/]-embroider-test-entrypoint.js/;
|
9
|
+
function decodeTestEntrypoint(filename) {
|
10
|
+
// Performance: avoid paying regex exec cost unless needed
|
11
|
+
if (!filename.includes('-embroider-test-entrypoint.js')) {
|
12
|
+
return;
|
13
|
+
}
|
14
|
+
let m = entrypointPattern.exec(filename);
|
15
|
+
if (m) {
|
16
|
+
return {
|
17
|
+
fromFile: m.groups.filename,
|
18
|
+
};
|
19
|
+
}
|
20
|
+
}
|
21
|
+
exports.decodeTestEntrypoint = decodeTestEntrypoint;
|
22
|
+
function renderTestEntrypoint(resolver, { fromFile }) {
|
23
|
+
const owner = resolver.packageCache.ownerOfFile(fromFile);
|
24
|
+
if (!owner) {
|
25
|
+
throw new Error(`Owner expected while loading test entrypoint from file: ${fromFile}`);
|
26
|
+
}
|
27
|
+
let engine = resolver.owningEngine(owner);
|
28
|
+
let appFiles = new app_files_1.AppFiles({
|
29
|
+
package: owner,
|
30
|
+
addons: new Map(engine.activeAddons.map(addon => [
|
31
|
+
resolver.packageCache.get(addon.root),
|
32
|
+
addon.canResolveFromFile,
|
33
|
+
])),
|
34
|
+
isApp: true,
|
35
|
+
modulePrefix: resolver.options.modulePrefix,
|
36
|
+
appRelativePath: 'NOT_USED_DELETE_ME',
|
37
|
+
}, (0, virtual_entrypoint_1.getAppFiles)(owner.root), new Set(), // no fastboot files
|
38
|
+
(0, shared_internals_1.extensionsPattern)(resolver.options.resolvableExtensions), (0, virtual_entrypoint_1.staticAppPathsPattern)(resolver.options.staticAppPaths), resolver.options.podModulePrefix);
|
39
|
+
let amdModules = [];
|
40
|
+
for (let relativePath of appFiles.tests) {
|
41
|
+
amdModules.push((0, virtual_entrypoint_1.importPaths)(resolver, appFiles, relativePath));
|
42
|
+
}
|
43
|
+
let src = entryTemplate({
|
44
|
+
amdModules,
|
45
|
+
});
|
46
|
+
return {
|
47
|
+
src,
|
48
|
+
watches: [],
|
49
|
+
};
|
50
|
+
}
|
51
|
+
exports.renderTestEntrypoint = renderTestEntrypoint;
|
52
|
+
const entryTemplate = (0, js_handlebars_1.compile)(`
|
53
|
+
import { importSync as i } from '@embroider/macros';
|
54
|
+
let w = window;
|
55
|
+
let d = w.define;
|
56
|
+
|
57
|
+
import "ember-testing";
|
58
|
+
import "@embroider/core/entrypoint";
|
59
|
+
|
60
|
+
{{#each amdModules as |amdModule| ~}}
|
61
|
+
d("{{js-string-escape amdModule.runtime}}", function(){ return i("{{js-string-escape amdModule.buildtime}}");});
|
62
|
+
{{/each}}
|
63
|
+
|
64
|
+
import('./tests/test-helper');
|
65
|
+
EmberENV.TESTS_FILE_LOADED = true;
|
66
|
+
`);
|
67
|
+
//# sourceMappingURL=virtual-test-entrypoint.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"virtual-test-entrypoint.js","sourceRoot":"","sources":["virtual-test-entrypoint.ts"],"names":[],"mappings":";;;AAAA,2CAAuC;AACvC,mDAA0C;AAE1C,kEAAgE;AAEhE,6DAAuF;AAEvF,MAAM,iBAAiB,GAAG,mDAAmD,CAAC;AAE9E,SAAgB,oBAAoB,CAAC,QAAgB;IACnD,0DAA0D;IAC1D,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,+BAA+B,CAAC,EAAE,CAAC;QACxD,OAAO;IACT,CAAC;IACD,IAAI,CAAC,GAAG,iBAAiB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACzC,IAAI,CAAC,EAAE,CAAC;QACN,OAAO;YACL,QAAQ,EAAE,CAAC,CAAC,MAAO,CAAC,QAAQ;SAC7B,CAAC;IACJ,CAAC;AACH,CAAC;AAXD,oDAWC;AAED,SAAgB,oBAAoB,CAClC,QAAkB,EAClB,EAAE,QAAQ,EAAwB;IAElC,MAAM,KAAK,GAAG,QAAQ,CAAC,YAAY,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;IAE1D,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CAAC,2DAA2D,QAAQ,EAAE,CAAC,CAAC;IACzF,CAAC;IAED,IAAI,MAAM,GAAG,QAAQ,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;IAE1C,IAAI,QAAQ,GAAG,IAAI,oBAAQ,CACzB;QACE,OAAO,EAAE,KAAK;QACd,MAAM,EAAE,IAAI,GAAG,CACb,MAAM,CAAC,YAAY,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;YAC/B,QAAQ,CAAC,YAAY,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAmB;YACvD,KAAK,CAAC,kBAAkB;SACzB,CAAC,CACH;QACD,KAAK,EAAE,IAAI;QACX,YAAY,EAAE,QAAQ,CAAC,OAAO,CAAC,YAAY;QAC3C,eAAe,EAAE,oBAAoB;KACtC,EACD,IAAA,gCAAW,EAAC,KAAK,CAAC,IAAI,CAAC,EACvB,IAAI,GAAG,EAAE,EAAE,oBAAoB;IAC/B,IAAA,oCAAiB,EAAC,QAAQ,CAAC,OAAO,CAAC,oBAAoB,CAAC,EACxD,IAAA,0CAAqB,EAAC,QAAQ,CAAC,OAAO,CAAC,cAAc,CAAC,EACtD,QAAQ,CAAC,OAAO,CAAC,eAAe,CACjC,CAAC;IAEF,IAAI,UAAU,GAA6C,EAAE,CAAC;IAE9D,KAAK,IAAI,YAAY,IAAI,QAAQ,CAAC,KAAK,EAAE,CAAC;QACxC,UAAU,CAAC,IAAI,CAAC,IAAA,gCAAW,EAAC,QAAQ,EAAE,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAC;IACjE,CAAC;IAED,IAAI,GAAG,GAAG,aAAa,CAAC;QACtB,UAAU;KACX,CAAC,CAAC;IAEH,OAAO;QACL,GAAG;QACH,OAAO,EAAE,EAAE;KACZ,CAAC;AACJ,CAAC;AA9CD,oDA8CC;AAED,MAAM,aAAa,GAAG,IAAA,uBAAO,EAAC;;;;;;;;;;;;;;CAc7B,CAAiF,CAAC","sourcesContent":["import { AppFiles } from './app-files';\nimport { compile } from './js-handlebars';\nimport type { Resolver } from './module-resolver';\nimport { extensionsPattern } from '@embroider/shared-internals';\nimport type { V2AddonPackage } from '@embroider/shared-internals/src/package';\nimport { getAppFiles, importPaths, staticAppPathsPattern } from './virtual-entrypoint';\n\nconst entrypointPattern = /(?<filename>.*)[\\\\/]-embroider-test-entrypoint.js/;\n\nexport function decodeTestEntrypoint(filename: string): { fromFile: string } | undefined {\n // Performance: avoid paying regex exec cost unless needed\n if (!filename.includes('-embroider-test-entrypoint.js')) {\n return;\n }\n let m = entrypointPattern.exec(filename);\n if (m) {\n return {\n fromFile: m.groups!.filename,\n };\n }\n}\n\nexport function renderTestEntrypoint(\n resolver: Resolver,\n { fromFile }: { fromFile: string }\n): { src: string; watches: string[] } {\n const owner = resolver.packageCache.ownerOfFile(fromFile);\n\n if (!owner) {\n throw new Error(`Owner expected while loading test entrypoint from file: ${fromFile}`);\n }\n\n let engine = resolver.owningEngine(owner);\n\n let appFiles = new AppFiles(\n {\n package: owner,\n addons: new Map(\n engine.activeAddons.map(addon => [\n resolver.packageCache.get(addon.root) as V2AddonPackage,\n addon.canResolveFromFile,\n ])\n ),\n isApp: true,\n modulePrefix: resolver.options.modulePrefix,\n appRelativePath: 'NOT_USED_DELETE_ME',\n },\n getAppFiles(owner.root),\n new Set(), // no fastboot files\n extensionsPattern(resolver.options.resolvableExtensions),\n staticAppPathsPattern(resolver.options.staticAppPaths),\n resolver.options.podModulePrefix\n );\n\n let amdModules: { runtime: string; buildtime: string }[] = [];\n\n for (let relativePath of appFiles.tests) {\n amdModules.push(importPaths(resolver, appFiles, relativePath));\n }\n\n let src = entryTemplate({\n amdModules,\n });\n\n return {\n src,\n watches: [],\n };\n}\n\nconst entryTemplate = compile(`\nimport { importSync as i } from '@embroider/macros';\nlet w = window;\nlet d = w.define;\n\nimport \"ember-testing\";\nimport \"@embroider/core/entrypoint\";\n\n{{#each amdModules as |amdModule| ~}}\n d(\"{{js-string-escape amdModule.runtime}}\", function(){ return i(\"{{js-string-escape amdModule.buildtime}}\");});\n{{/each}}\n\nimport('./tests/test-helper');\nEmberENV.TESTS_FILE_LOADED = true;\n`) as (params: { amdModules: { runtime: string; buildtime: string }[] }) => string;\n"]}
|
@@ -27,17 +27,23 @@ function getVendorStyles(owner, resolver) {
|
|
27
27
|
resolver.packageCache.get(addon.root),
|
28
28
|
addon.canResolveFromFile,
|
29
29
|
])),
|
30
|
-
isApp:
|
30
|
+
isApp: engineConfig.root === resolver.options.engines[0].root,
|
31
31
|
modulePrefix: resolver.options.modulePrefix,
|
32
32
|
appRelativePath: 'NOT_USED_DELETE_ME',
|
33
33
|
};
|
34
34
|
return generateVendorStyles(engine);
|
35
35
|
}
|
36
36
|
function generateVendorStyles(engine) {
|
37
|
-
let result = impliedAddonVendorStyles(engine).map(
|
38
|
-
|
39
|
-
|
40
|
-
|
37
|
+
let result = impliedAddonVendorStyles(engine).map(sourcePath => (0, fs_1.readFileSync)(sourcePath, 'utf-8'));
|
38
|
+
// add the engines own styles but only if it is not the top-level app, that is provided by @embroider/synthesized-styles
|
39
|
+
if (!engine.isApp) {
|
40
|
+
let engineStyles = [];
|
41
|
+
engineStyles = getAddonImplicitStyles(engine.package).map(sourcePath => (0, fs_1.readFileSync)(sourcePath, 'utf-8'));
|
42
|
+
// add engine's own implicit styles after all vendor styles
|
43
|
+
if (engineStyles.length) {
|
44
|
+
result = [...result, ...engineStyles];
|
45
|
+
}
|
46
|
+
}
|
41
47
|
return result.join('');
|
42
48
|
}
|
43
49
|
function impliedAddonVendorStyles(engine) {
|
@@ -52,21 +58,26 @@ function impliedAddonVendorStyles(engine) {
|
|
52
58
|
return 1000;
|
53
59
|
}
|
54
60
|
})) {
|
55
|
-
|
56
|
-
if (
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
styles.push(resolve_1.default.sync(mod, options));
|
63
|
-
}
|
64
|
-
}
|
65
|
-
if (styles.length) {
|
66
|
-
result = [...styles, ...result];
|
67
|
-
}
|
61
|
+
// exclude lazy engines because they will handle their own css importation
|
62
|
+
if (addon.isLazyEngine()) {
|
63
|
+
continue;
|
64
|
+
}
|
65
|
+
let styles = getAddonImplicitStyles(addon);
|
66
|
+
if (styles.length) {
|
67
|
+
result = [...styles, ...result];
|
68
68
|
}
|
69
69
|
}
|
70
70
|
return result;
|
71
71
|
}
|
72
|
+
function getAddonImplicitStyles(pkg) {
|
73
|
+
let implicitStyles = pkg.meta['implicit-styles'];
|
74
|
+
let styles = [];
|
75
|
+
if (implicitStyles) {
|
76
|
+
let options = { basedir: pkg.root };
|
77
|
+
for (let mod of implicitStyles) {
|
78
|
+
styles.push(resolve_1.default.sync(mod, options));
|
79
|
+
}
|
80
|
+
}
|
81
|
+
return styles;
|
82
|
+
}
|
72
83
|
//# sourceMappingURL=virtual-vendor-styles.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"virtual-vendor-styles.js","sourceRoot":"","sources":["virtual-vendor-styles.ts"],"names":[],"mappings":";;;;;;AAEA,2BAAkC;AAClC,mCAAgC;AAChC,sDAA8B;AAK9B,SAAgB,yBAAyB,CAAC,QAAgB;IACxD,OAAO,QAAQ,CAAC,QAAQ,CAAC,8BAA8B,CAAC,CAAC;AAC3D,CAAC;AAFD,8DAEC;AAED,SAAgB,kBAAkB,CAAC,QAAgB,EAAE,QAAkB;IACrE,MAAM,KAAK,GAAG,QAAQ,CAAC,YAAY,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;IAC1D,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CAAC,oCAAoC,QAAQ,EAAE,CAAC,CAAC;IAClE,CAAC;IACD,OAAO,EAAE,GAAG,EAAE,eAAe,CAAC,KAAK,EAAE,QAAQ,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;AAChE,CAAC;AAND,gDAMC;AAED,SAAS,eAAe,CAAC,KAAc,EAAE,QAAkB;IACzD,IAAI,YAAY,GAAG,QAAQ,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;IAChD,IAAI,MAAM,GAAW;QACnB,OAAO,EAAE,KAAK;QACd,MAAM,EAAE,IAAI,GAAG,CACb,YAAY,CAAC,YAAY,CAA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;QACH,0EAA0E;QAC1E,IAAI,KAAK,CAAC,YAAY,EAAE,EAAE,CAAC;YACzB,SAAS;QACX,CAAC;QAED,IAAI,MAAM,GAAG,sBAAsB,CAAC,KAAK,CAAC,CAAC;QAE3C,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;YAClB,MAAM,GAAG,CAAC,GAAG,MAAM,EAAE,GAAG,MAAM,CAAC,CAAC;QAClC,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,sBAAsB,CAAC,GAAmB;IACjD,IAAI,cAAc,GAAG,GAAG,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;IACjD,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,IAAI,cAAc,EAAE,CAAC;QACnB,IAAI,OAAO,GAAG,EAAE,OAAO,EAAE,GAAG,CAAC,IAAI,EAAE,CAAC;QACpC,KAAK,IAAI,GAAG,IAAI,cAAc,EAAE,CAAC;YAC/B,MAAM,CAAC,IAAI,CAAC,iBAAO,CAAC,IAAI,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC;QAC1C,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import type { Package } from '@embroider/shared-internals';\nimport type { V2AddonPackage } from '@embroider/shared-internals/src/package';\nimport { readFileSync } from 'fs';\nimport { sortBy } from 'lodash';\nimport resolve from 'resolve';\nimport type { Resolver } from './module-resolver';\nimport type { VirtualContentResult } from './virtual-content';\nimport type { Engine } from './app-files';\n\nexport function decodeVirtualVendorStyles(filename: string): boolean {\n return filename.endsWith('-embroider-vendor-styles.css');\n}\n\nexport function renderVendorStyles(filename: string, resolver: Resolver): VirtualContentResult {\n const owner = resolver.packageCache.ownerOfFile(filename);\n if (!owner) {\n throw new Error(`Failed to find a valid owner for ${filename}`);\n }\n return { src: getVendorStyles(owner, resolver), watches: [] };\n}\n\nfunction getVendorStyles(owner: Package, resolver: Resolver): string {\n let engineConfig = resolver.owningEngine(owner);\n let engine: Engine = {\n package: owner,\n addons: new Map(\n engineConfig.activeAddons.map(addon => [\n resolver.packageCache.get(addon.root) as V2AddonPackage,\n addon.canResolveFromFile,\n ])\n ),\n isApp: engineConfig.root === resolver.options.engines[0].root,\n modulePrefix: resolver.options.modulePrefix,\n appRelativePath: 'NOT_USED_DELETE_ME',\n };\n\n return generateVendorStyles(engine);\n}\n\nfunction generateVendorStyles(engine: Engine): string {\n let result: string[] = impliedAddonVendorStyles(engine).map(sourcePath => readFileSync(sourcePath, 'utf-8'));\n\n // add the engines own styles but only if it is not the top-level app, that is provided by @embroider/synthesized-styles\n if (!engine.isApp) {\n let engineStyles = [];\n\n engineStyles = getAddonImplicitStyles(engine.package as V2AddonPackage).map(sourcePath =>\n readFileSync(sourcePath, 'utf-8')\n );\n\n // add engine's own implicit styles after all vendor styles\n if (engineStyles.length) {\n result = [...result, ...engineStyles];\n }\n }\n\n return result.join('') as string;\n}\n\nfunction impliedAddonVendorStyles(engine: Engine): string[] {\n let result: Array<string> = [];\n for (let addon of sortBy(Array.from(engine.addons.keys()), pkg => {\n switch (pkg.name) {\n case 'loader.js':\n return 0;\n case 'ember-source':\n return 10;\n default:\n return 1000;\n }\n })) {\n // exclude lazy engines because they will handle their own css importation\n if (addon.isLazyEngine()) {\n continue;\n }\n\n let styles = getAddonImplicitStyles(addon);\n\n if (styles.length) {\n result = [...styles, ...result];\n }\n }\n return result;\n}\n\nfunction getAddonImplicitStyles(pkg: V2AddonPackage): string[] {\n let implicitStyles = pkg.meta['implicit-styles'];\n let styles = [];\n if (implicitStyles) {\n let options = { basedir: pkg.root };\n for (let mod of implicitStyles) {\n styles.push(resolve.sync(mod, options));\n }\n }\n return styles;\n}\n"]}
|
package/src/asset.d.ts
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
/// <reference types="node" />
|
2
|
-
/// <reference types="jsdom/ts4.0" />
|
3
|
-
/// <reference types="jsdom/base" />
|
4
|
-
import type { JSDOM } from 'jsdom';
|
5
|
-
import type { EmberHTML } from './ember-html';
|
6
|
-
export interface ImplicitAssetPaths {
|
7
|
-
'implicit-scripts': string[];
|
8
|
-
'implicit-test-scripts': string[];
|
9
|
-
'implicit-styles': string[];
|
10
|
-
'implicit-test-styles': string[];
|
11
|
-
}
|
12
|
-
interface BaseAsset {
|
13
|
-
relativePath: string;
|
14
|
-
}
|
15
|
-
export interface OnDiskAsset extends BaseAsset {
|
16
|
-
kind: 'on-disk';
|
17
|
-
sourcePath: string;
|
18
|
-
mtime: number;
|
19
|
-
size: number;
|
20
|
-
}
|
21
|
-
export interface InMemoryAsset extends BaseAsset {
|
22
|
-
kind: 'in-memory';
|
23
|
-
source: string | Buffer;
|
24
|
-
}
|
25
|
-
export interface EmberAsset extends BaseAsset {
|
26
|
-
kind: 'ember';
|
27
|
-
sourcePath: string;
|
28
|
-
mtime: number;
|
29
|
-
size: number;
|
30
|
-
includeTests: boolean;
|
31
|
-
rootURL: string;
|
32
|
-
prepare(dom: JSDOM): EmberHTML;
|
33
|
-
}
|
34
|
-
export type Asset = OnDiskAsset | InMemoryAsset | EmberAsset;
|
35
|
-
export {};
|
package/src/asset.js
DELETED
package/src/asset.js.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"asset.js","sourceRoot":"","sources":["asset.ts"],"names":[],"mappings":"","sourcesContent":["import type { JSDOM } from 'jsdom';\nimport type { EmberHTML } from './ember-html';\n\nexport interface ImplicitAssetPaths {\n 'implicit-scripts': string[];\n 'implicit-test-scripts': string[];\n 'implicit-styles': string[];\n 'implicit-test-styles': string[];\n}\n\ninterface BaseAsset {\n // where this asset should be placed, relative to the app's root\n relativePath: string;\n}\n\nexport interface OnDiskAsset extends BaseAsset {\n kind: 'on-disk';\n\n // absolute path to where we will find it\n sourcePath: string;\n mtime: number;\n size: number;\n}\n\nexport interface InMemoryAsset extends BaseAsset {\n kind: 'in-memory';\n\n // the actual bits\n source: string | Buffer;\n}\n\n// This represents an HTML entrypoint to the Ember app\nexport interface EmberAsset extends BaseAsset {\n kind: 'ember';\n\n // absolute path to where we will find the html file\n sourcePath: string;\n\n // these describe the file at sourcePath so we can avoid rebuilding when it\n // hasn't changed\n mtime: number;\n size: number;\n\n // whether we should include the test suite (in addition to the ember app)\n includeTests: boolean;\n\n // the rootURL at which this Ember app expects to be hosted.\n rootURL: string;\n\n // This will receive the parsed document. It may optionally modify the\n // document. And it must return a description of the locations where we're\n // supposed to insert the parts of the Ember app.\n prepare(dom: JSDOM): EmberHTML;\n}\n\nexport type Asset = OnDiskAsset | InMemoryAsset | EmberAsset;\n"]}
|
package/src/ember-html.d.ts
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
/// <reference types="jsdom/ts4.0" />
|
2
|
-
/// <reference types="jsdom/base" />
|
3
|
-
import { JSDOM } from 'jsdom';
|
4
|
-
import type { EmberAsset } from './asset';
|
5
|
-
export interface EmberHTML {
|
6
|
-
javascript: Node;
|
7
|
-
styles: Node;
|
8
|
-
implicitScripts: Node;
|
9
|
-
implicitStyles: Node;
|
10
|
-
testJavascript?: Node;
|
11
|
-
implicitTestScripts?: Node;
|
12
|
-
implicitTestStyles?: Node;
|
13
|
-
}
|
14
|
-
declare class Placeholder {
|
15
|
-
readonly start: Node;
|
16
|
-
readonly end: Node;
|
17
|
-
readonly reference: Node;
|
18
|
-
static replacing(node: Node): Placeholder;
|
19
|
-
static immediatelyAfter(node: Node): Placeholder;
|
20
|
-
readonly parent: HTMLElement;
|
21
|
-
constructor(start: Node, end: Node, reference: Node);
|
22
|
-
clear(): void;
|
23
|
-
insert(node: Node): void;
|
24
|
-
}
|
25
|
-
export declare class PreparedEmberHTML {
|
26
|
-
private asset;
|
27
|
-
dom: JSDOM;
|
28
|
-
javascript: Placeholder;
|
29
|
-
styles: Placeholder;
|
30
|
-
implicitScripts: Placeholder;
|
31
|
-
implicitStyles: Placeholder;
|
32
|
-
testJavascript: Placeholder;
|
33
|
-
implicitTestScripts: Placeholder;
|
34
|
-
implicitTestStyles: Placeholder;
|
35
|
-
constructor(asset: EmberAsset);
|
36
|
-
private placeholders;
|
37
|
-
clear(): void;
|
38
|
-
insertScriptTag(placeholder: Placeholder, relativeSrc: string, { type, tag }?: {
|
39
|
-
type?: string;
|
40
|
-
tag?: string;
|
41
|
-
}): void;
|
42
|
-
insertStyleLink(placeholder: Placeholder, relativeHref: string): void;
|
43
|
-
}
|
44
|
-
export declare function insertNewline(at: Node): void;
|
45
|
-
export {};
|
package/src/ember-html.js
DELETED
@@ -1,110 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.insertNewline = exports.PreparedEmberHTML = void 0;
|
4
|
-
const jsdom_1 = require("jsdom");
|
5
|
-
const fs_1 = require("fs");
|
6
|
-
const html_placeholder_1 = require("./html-placeholder");
|
7
|
-
class Placeholder {
|
8
|
-
static replacing(node) {
|
9
|
-
let placeholder = this.immediatelyAfter(node);
|
10
|
-
node.parentElement.removeChild(node);
|
11
|
-
return placeholder;
|
12
|
-
}
|
13
|
-
static immediatelyAfter(node) {
|
14
|
-
let document = node.ownerDocument;
|
15
|
-
let parent = node.parentElement;
|
16
|
-
if (!document || !parent) {
|
17
|
-
throw new Error('Cannot make Placeholder out of detached node');
|
18
|
-
}
|
19
|
-
let nextSibling = node.nextSibling;
|
20
|
-
let start = document.createTextNode('');
|
21
|
-
let end = document.createTextNode('');
|
22
|
-
parent.insertBefore(start, nextSibling);
|
23
|
-
parent.insertBefore(end, nextSibling);
|
24
|
-
return new Placeholder(start, end, node);
|
25
|
-
}
|
26
|
-
constructor(start, end, reference) {
|
27
|
-
this.start = start;
|
28
|
-
this.end = end;
|
29
|
-
this.reference = reference;
|
30
|
-
if (start.parentElement && start.parentElement === end.parentElement) {
|
31
|
-
this.parent = start.parentElement;
|
32
|
-
}
|
33
|
-
else {
|
34
|
-
throw new Error('Cannot make Placeholder out of detached node');
|
35
|
-
}
|
36
|
-
}
|
37
|
-
clear() {
|
38
|
-
let { start, end, parent } = this;
|
39
|
-
while (start.nextSibling && start.nextSibling !== end) {
|
40
|
-
parent.removeChild(start.nextSibling);
|
41
|
-
}
|
42
|
-
}
|
43
|
-
insert(node) {
|
44
|
-
this.parent.insertBefore(node, this.end);
|
45
|
-
}
|
46
|
-
}
|
47
|
-
class PreparedEmberHTML {
|
48
|
-
constructor(asset) {
|
49
|
-
this.asset = asset;
|
50
|
-
this.dom = new jsdom_1.JSDOM((0, fs_1.readFileSync)(asset.sourcePath, 'utf8'));
|
51
|
-
let html = asset.prepare(this.dom);
|
52
|
-
this.javascript = Placeholder.replacing(html.javascript);
|
53
|
-
this.styles = Placeholder.replacing(html.styles);
|
54
|
-
this.implicitScripts = Placeholder.replacing(html.implicitScripts);
|
55
|
-
this.implicitStyles = Placeholder.replacing(html.implicitStyles);
|
56
|
-
this.testJavascript = html.testJavascript
|
57
|
-
? Placeholder.replacing(html.testJavascript)
|
58
|
-
: Placeholder.immediatelyAfter(this.javascript.end);
|
59
|
-
this.implicitTestScripts = html.implicitTestScripts
|
60
|
-
? Placeholder.replacing(html.implicitTestScripts)
|
61
|
-
: Placeholder.immediatelyAfter(this.implicitScripts.end);
|
62
|
-
this.implicitTestStyles = html.implicitTestStyles
|
63
|
-
? Placeholder.replacing(html.implicitTestStyles)
|
64
|
-
: Placeholder.immediatelyAfter(this.implicitStyles.end);
|
65
|
-
}
|
66
|
-
placeholders() {
|
67
|
-
return [
|
68
|
-
this.javascript,
|
69
|
-
this.styles,
|
70
|
-
this.implicitScripts,
|
71
|
-
this.implicitStyles,
|
72
|
-
this.implicitTestScripts,
|
73
|
-
this.implicitTestStyles,
|
74
|
-
this.testJavascript,
|
75
|
-
];
|
76
|
-
}
|
77
|
-
clear() {
|
78
|
-
for (let range of this.placeholders()) {
|
79
|
-
range.clear();
|
80
|
-
}
|
81
|
-
}
|
82
|
-
// this takes the src relative to the application root, we adjust it so it's
|
83
|
-
// root-relative via the configured rootURL
|
84
|
-
insertScriptTag(placeholder, relativeSrc, { type, tag = 'script' } = {}) {
|
85
|
-
let document = this.dom.window.document;
|
86
|
-
let from = placeholder.reference.nodeType === 1 ? placeholder.reference : undefined;
|
87
|
-
let src = this.asset.rootURL + relativeSrc;
|
88
|
-
let attributes = type ? { src, type } : { src };
|
89
|
-
let newTag = (0, html_placeholder_1.makeTag)(document, { from, tag, attributes });
|
90
|
-
placeholder.insert(this.dom.window.document.createTextNode('\n'));
|
91
|
-
placeholder.insert(newTag);
|
92
|
-
}
|
93
|
-
// this takes the href relative to the application root, we adjust it so it's
|
94
|
-
// root-relative via the configured rootURL
|
95
|
-
insertStyleLink(placeholder, relativeHref) {
|
96
|
-
let document = this.dom.window.document;
|
97
|
-
let from = placeholder.reference.nodeType === 1 ? placeholder.reference : undefined;
|
98
|
-
let href = this.asset.rootURL + relativeHref;
|
99
|
-
let newTag = (0, html_placeholder_1.makeTag)(document, { from, tag: 'link', attributes: { href } });
|
100
|
-
(0, html_placeholder_1.normalizeStyleLink)(newTag);
|
101
|
-
placeholder.insert(this.dom.window.document.createTextNode('\n'));
|
102
|
-
placeholder.insert(newTag);
|
103
|
-
}
|
104
|
-
}
|
105
|
-
exports.PreparedEmberHTML = PreparedEmberHTML;
|
106
|
-
function insertNewline(at) {
|
107
|
-
at.parentElement.insertBefore(at.ownerDocument.createTextNode('\n'), at);
|
108
|
-
}
|
109
|
-
exports.insertNewline = insertNewline;
|
110
|
-
//# sourceMappingURL=ember-html.js.map
|
package/src/ember-html.js.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"ember-html.js","sourceRoot":"","sources":["ember-html.ts"],"names":[],"mappings":";;;AAAA,iCAA8B;AAC9B,2BAAkC;AAElC,yDAAiE;AAyBjE,MAAM,WAAW;IACf,MAAM,CAAC,SAAS,CAAC,IAAU;QACzB,IAAI,WAAW,GAAG,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC;QAC9C,IAAI,CAAC,aAAc,CAAC,WAAW,CAAC,IAAI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IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC;QAClE,WAAW,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAC7B,CAAC;IAED,6EAA6E;IAC7E,2CAA2C;IAC3C,eAAe,CAAC,WAAwB,EAAE,YAAoB;QAC5D,IAAI,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC;QACxC,IAAI,IAAI,GAAG,WAAW,CAAC,SAAS,CAAC,QAAQ,KAAK,CAAC,CAAC,CAAC,CAAE,WAAW,CAAC,SAAyB,CAAC,CAAC,CAAC,SAAS,CAAC;QACrG,IAAI,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,YAAY,CAAC;QAC7C,IAAI,MAAM,GAAG,IAAA,0BAAO,EAAC,QAAQ,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC;QAC5E,IAAA,qCAAkB,EAAC,MAAM,CAAC,CAAC;QAC3B,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC;QAClE,WAAW,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAC7B,CAAC;CACF;AAzED,8CAyEC;AAED,SAAgB,aAAa,CAAC,EAAQ;IACpC,EAAE,CAAC,aAAc,CAAC,YAAY,CAAC,EAAE,CAAC,aAAc,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC;AAC7E,CAAC;AAFD,sCAEC","sourcesContent":["import { JSDOM } from 'jsdom';\nimport { readFileSync } from 'fs';\nimport type { EmberAsset } from './asset';\nimport { makeTag, normalizeStyleLink } from './html-placeholder';\n\nexport interface EmberHTML {\n // each of the Nodes in here points at where we should insert the\n // corresponding parts of the ember app. The Nodes themselves will be\n // replaced, so provide placeholders.\n\n // these are mandatory, the Ember app may need to put things into them.\n javascript: Node;\n styles: Node;\n implicitScripts: Node;\n implicitStyles: Node;\n\n // these are optional because you *may* choose to stick your implicit test\n // things into specific locations (which we need for backward-compat). But you\n // can leave these off and we will simply put them in the same places as the\n // non-test things.\n //\n // Do not confuse these with controlling whether or not we will insert tests.\n // That is separately controlled via `includeTests`.\n testJavascript?: Node;\n implicitTestScripts?: Node;\n implicitTestStyles?: Node;\n}\n\nclass Placeholder {\n static replacing(node: Node): Placeholder {\n let placeholder = this.immediatelyAfter(node);\n node.parentElement!.removeChild(node);\n return placeholder;\n }\n\n static immediatelyAfter(node: Node): Placeholder {\n let document = node.ownerDocument;\n let parent = node.parentElement;\n\n if (!document || !parent) {\n throw new Error('Cannot make Placeholder out of detached node');\n }\n\n let nextSibling = node.nextSibling;\n let start = document.createTextNode('');\n let end = document.createTextNode('');\n\n parent.insertBefore(start, nextSibling);\n parent.insertBefore(end, nextSibling);\n return new Placeholder(start, end, node);\n }\n\n readonly parent: HTMLElement;\n\n constructor(readonly start: Node, readonly end: Node, readonly reference: Node) {\n if (start.parentElement && start.parentElement === end.parentElement) {\n this.parent = start.parentElement;\n } else {\n throw new Error('Cannot make Placeholder out of detached node');\n }\n }\n\n clear() {\n let { start, end, parent } = this;\n while (start.nextSibling && start.nextSibling !== end) {\n parent.removeChild(start.nextSibling);\n }\n }\n\n insert(node: Node) {\n this.parent.insertBefore(node, this.end);\n }\n}\n\nexport class PreparedEmberHTML {\n dom: JSDOM;\n javascript: Placeholder;\n styles: Placeholder;\n implicitScripts: Placeholder;\n implicitStyles: Placeholder;\n testJavascript: Placeholder;\n implicitTestScripts: Placeholder;\n implicitTestStyles: Placeholder;\n\n constructor(private asset: EmberAsset) {\n this.dom = new JSDOM(readFileSync(asset.sourcePath, 'utf8'));\n let html = asset.prepare(this.dom);\n this.javascript = Placeholder.replacing(html.javascript);\n this.styles = Placeholder.replacing(html.styles);\n this.implicitScripts = Placeholder.replacing(html.implicitScripts);\n this.implicitStyles = Placeholder.replacing(html.implicitStyles);\n this.testJavascript = html.testJavascript\n ? Placeholder.replacing(html.testJavascript)\n : Placeholder.immediatelyAfter(this.javascript.end);\n this.implicitTestScripts = html.implicitTestScripts\n ? Placeholder.replacing(html.implicitTestScripts)\n : Placeholder.immediatelyAfter(this.implicitScripts.end);\n this.implicitTestStyles = html.implicitTestStyles\n ? Placeholder.replacing(html.implicitTestStyles)\n : Placeholder.immediatelyAfter(this.implicitStyles.end);\n }\n\n private placeholders(): Placeholder[] {\n return [\n this.javascript,\n this.styles,\n this.implicitScripts,\n this.implicitStyles,\n this.implicitTestScripts,\n this.implicitTestStyles,\n this.testJavascript,\n ];\n }\n\n clear() {\n for (let range of this.placeholders()) {\n range.clear();\n }\n }\n\n // this takes the src relative to the application root, we adjust it so it's\n // root-relative via the configured rootURL\n insertScriptTag(\n placeholder: Placeholder,\n relativeSrc: string,\n { type, tag = 'script' }: { type?: string; tag?: string } = {}\n ) {\n let document = this.dom.window.document;\n let from = placeholder.reference.nodeType === 1 ? (placeholder.reference as HTMLElement) : undefined;\n let src = this.asset.rootURL + relativeSrc;\n let attributes: Record<string, string> = type ? { src, type } : { src };\n let newTag = makeTag(document, { from, tag, attributes });\n placeholder.insert(this.dom.window.document.createTextNode('\\n'));\n placeholder.insert(newTag);\n }\n\n // this takes the href relative to the application root, we adjust it so it's\n // root-relative via the configured rootURL\n insertStyleLink(placeholder: Placeholder, relativeHref: string) {\n let document = this.dom.window.document;\n let from = placeholder.reference.nodeType === 1 ? (placeholder.reference as HTMLElement) : undefined;\n let href = this.asset.rootURL + relativeHref;\n let newTag = makeTag(document, { from, tag: 'link', attributes: { href } });\n normalizeStyleLink(newTag);\n placeholder.insert(this.dom.window.document.createTextNode('\\n'));\n placeholder.insert(newTag);\n }\n}\n\nexport function insertNewline(at: Node) {\n at.parentElement!.insertBefore(at.ownerDocument!.createTextNode('\\n'), at);\n}\n"]}
|