ng-packagr 18.0.0-next.4 → 18.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/lib/flatten/file-loader-plugin.d.ts +6 -0
- package/lib/flatten/file-loader-plugin.js +49 -0
- package/lib/flatten/file-loader-plugin.js.map +1 -0
- package/lib/flatten/rollup.d.ts +23 -0
- package/lib/flatten/rollup.js +110 -0
- package/lib/flatten/rollup.js.map +1 -0
- package/lib/ng-package/entry-point/write-bundles.transform.js +67 -8
- package/lib/ng-package/entry-point/write-bundles.transform.js.map +1 -1
- package/lib/ng-package/nodes.d.ts +2 -2
- package/lib/ng-package/nodes.js.map +1 -1
- package/lib/ng-package/package.transform.js +1 -2
- package/lib/ng-package/package.transform.js.map +1 -1
- package/package.json +9 -3
- package/lib/flatten/esbuild.d.ts +0 -20
- package/lib/flatten/esbuild.js +0 -75
- package/lib/flatten/esbuild.js.map +0 -1
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.fileLoaderPlugin = void 0;
|
|
27
|
+
const log = __importStar(require("../utils/log"));
|
|
28
|
+
const path_1 = require("../utils/path");
|
|
29
|
+
/**
|
|
30
|
+
* Loads a file and it's map.
|
|
31
|
+
*/
|
|
32
|
+
function fileLoaderPlugin(fileCache) {
|
|
33
|
+
return {
|
|
34
|
+
name: 'file-loader',
|
|
35
|
+
load: function (id) {
|
|
36
|
+
log.debug(`file-loader ${id}`);
|
|
37
|
+
const data = fileCache.get((0, path_1.ensureUnixPath)(id));
|
|
38
|
+
if (!data) {
|
|
39
|
+
throw new Error(`Could not load '${id}' from memory.`);
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
code: data.content,
|
|
43
|
+
map: data.map,
|
|
44
|
+
};
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
exports.fileLoaderPlugin = fileLoaderPlugin;
|
|
49
|
+
//# sourceMappingURL=file-loader-plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-loader-plugin.js","sourceRoot":"","sources":["../../../src/lib/flatten/file-loader-plugin.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,kDAAoC;AACpC,wCAA+C;AAE/C;;GAEG;AACH,SAAgB,gBAAgB,CAAC,SAA0B;IACzD,OAAO;QACL,IAAI,EAAE,aAAa;QACnB,IAAI,EAAE,UAAU,EAAE;YAChB,GAAG,CAAC,KAAK,CAAC,eAAe,EAAE,EAAE,CAAC,CAAC;YAE/B,MAAM,IAAI,GAAG,SAAS,CAAC,GAAG,CAAC,IAAA,qBAAc,EAAC,EAAE,CAAC,CAAC,CAAC;YAC/C,IAAI,CAAC,IAAI,EAAE,CAAC;gBACV,MAAM,IAAI,KAAK,CAAC,mBAAmB,EAAE,gBAAgB,CAAC,CAAC;YACzD,CAAC;YAED,OAAO;gBACL,IAAI,EAAE,IAAI,CAAC,OAAO;gBAClB,GAAG,EAAE,IAAI,CAAC,GAAG;aACd,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC;AAjBD,4CAiBC","sourcesContent":["import type { Plugin } from 'rollup';\nimport { OutputFileCache } from '../ng-package/nodes';\n\nimport * as log from '../utils/log';\nimport { ensureUnixPath } from '../utils/path';\n\n/**\n * Loads a file and it's map.\n */\nexport function fileLoaderPlugin(fileCache: OutputFileCache): Plugin {\n return {\n name: 'file-loader',\n load: function (id) {\n log.debug(`file-loader ${id}`);\n\n const data = fileCache.get(ensureUnixPath(id));\n if (!data) {\n throw new Error(`Could not load '${id}' from memory.`);\n }\n\n return {\n code: data.content,\n map: data.map,\n };\n },\n };\n}\n"]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { OutputAsset, OutputChunk, RollupCache } from 'rollup';
|
|
2
|
+
import { OutputFileCache } from '../ng-package/nodes';
|
|
3
|
+
/**
|
|
4
|
+
* Options used in `ng-packagr` for writing flat bundle files.
|
|
5
|
+
*
|
|
6
|
+
* These options are passed through to rollup.
|
|
7
|
+
*/
|
|
8
|
+
export interface RollupOptions {
|
|
9
|
+
moduleName: string;
|
|
10
|
+
entry: string;
|
|
11
|
+
entryName: string;
|
|
12
|
+
dir: string;
|
|
13
|
+
sourceRoot: string;
|
|
14
|
+
cache?: RollupCache;
|
|
15
|
+
cacheDirectory?: string | false;
|
|
16
|
+
fileCache: OutputFileCache;
|
|
17
|
+
cacheKey: string;
|
|
18
|
+
}
|
|
19
|
+
/** Runs rollup over the given entry file, writes a bundle file. */
|
|
20
|
+
export declare function rollupBundleFile(opts: RollupOptions): Promise<{
|
|
21
|
+
cache: RollupCache;
|
|
22
|
+
files: (OutputChunk | OutputAsset)[];
|
|
23
|
+
}>;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.rollupBundleFile = void 0;
|
|
30
|
+
const plugin_json_1 = __importDefault(require("@rollup/plugin-json"));
|
|
31
|
+
const plugin_node_resolve_1 = __importDefault(require("@rollup/plugin-node-resolve"));
|
|
32
|
+
const path = __importStar(require("path"));
|
|
33
|
+
const cache_1 = require("../utils/cache");
|
|
34
|
+
const log = __importStar(require("../utils/log"));
|
|
35
|
+
const file_loader_plugin_1 = require("./file-loader-plugin");
|
|
36
|
+
let rollup;
|
|
37
|
+
/** Runs rollup over the given entry file, writes a bundle file. */
|
|
38
|
+
async function rollupBundleFile(opts) {
|
|
39
|
+
var _a;
|
|
40
|
+
await ensureRollup();
|
|
41
|
+
log.debug(`rollup (v${rollup.VERSION}) ${opts.entry} to ${opts.dir}`);
|
|
42
|
+
const cacheDirectory = opts.cacheDirectory;
|
|
43
|
+
// Create the bundle
|
|
44
|
+
const bundle = await rollup.rollup({
|
|
45
|
+
context: 'this',
|
|
46
|
+
external: moduleId => isExternalDependency(moduleId),
|
|
47
|
+
cache: (_a = opts.cache) !== null && _a !== void 0 ? _a : (cacheDirectory ? await (0, cache_1.readCacheEntry)(cacheDirectory, opts.cacheKey) : undefined),
|
|
48
|
+
input: opts.entry,
|
|
49
|
+
plugins: [(0, plugin_node_resolve_1.default)(), (0, plugin_json_1.default)(), (0, file_loader_plugin_1.fileLoaderPlugin)(opts.fileCache)],
|
|
50
|
+
onwarn: warning => {
|
|
51
|
+
switch (warning.code) {
|
|
52
|
+
case 'CIRCULAR_DEPENDENCY':
|
|
53
|
+
case 'UNUSED_EXTERNAL_IMPORT':
|
|
54
|
+
case 'THIS_IS_UNDEFINED':
|
|
55
|
+
break;
|
|
56
|
+
default:
|
|
57
|
+
log.warn(warning.message);
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
preserveSymlinks: true,
|
|
62
|
+
// Disable treeshaking when generating bundles
|
|
63
|
+
// see: https://github.com/angular/angular/pull/32069
|
|
64
|
+
treeshake: false,
|
|
65
|
+
});
|
|
66
|
+
// Output the bundle to disk
|
|
67
|
+
const output = await bundle.write({
|
|
68
|
+
name: opts.moduleName,
|
|
69
|
+
format: 'es',
|
|
70
|
+
dir: opts.dir,
|
|
71
|
+
inlineDynamicImports: false,
|
|
72
|
+
chunkFileNames: opts.entryName + '-[name]-[hash].mjs',
|
|
73
|
+
entryFileNames: opts.entryName + '.mjs',
|
|
74
|
+
banner: '',
|
|
75
|
+
sourcemap: true,
|
|
76
|
+
});
|
|
77
|
+
if (cacheDirectory) {
|
|
78
|
+
await (0, cache_1.saveCacheEntry)(cacheDirectory, opts.cacheKey, JSON.stringify(bundle.cache));
|
|
79
|
+
}
|
|
80
|
+
// Close the bundle to let plugins clean up their external processes or services
|
|
81
|
+
await bundle.close();
|
|
82
|
+
return {
|
|
83
|
+
files: output.output,
|
|
84
|
+
cache: bundle.cache,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
exports.rollupBundleFile = rollupBundleFile;
|
|
88
|
+
async function ensureRollup() {
|
|
89
|
+
if (rollup) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
try {
|
|
93
|
+
rollup = await Promise.resolve().then(() => __importStar(require('rollup')));
|
|
94
|
+
log.debug(`rollup using native version.`);
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
rollup = await Promise.resolve().then(() => __importStar(require('@rollup/wasm-node')));
|
|
98
|
+
log.debug(`rollup using wasm version.`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
function isExternalDependency(moduleId) {
|
|
102
|
+
// more information about why we don't check for 'node_modules' path
|
|
103
|
+
// https://github.com/rollup/rollup-plugin-node-resolve/issues/110#issuecomment-350353632
|
|
104
|
+
if (moduleId.startsWith('.') || moduleId.startsWith('/') || path.isAbsolute(moduleId)) {
|
|
105
|
+
// if it's either 'absolute', marked to embed, starts with a '.' or '/' or is the umd bundle and is tslib
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=rollup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rollup.js","sourceRoot":"","sources":["../../../src/lib/flatten/rollup.ts"],"names":[],"mappings":";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GAAG,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;QACtF,yGAAyG;QACzG,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import rollupJson from '@rollup/plugin-json';\nimport nodeResolve from '@rollup/plugin-node-resolve';\nimport * as path from 'path';\nimport type { OutputAsset, OutputChunk, RollupCache } from 'rollup';\nimport { OutputFileCache } from '../ng-package/nodes';\nimport { readCacheEntry, saveCacheEntry } from '../utils/cache';\nimport * as log from '../utils/log';\nimport { fileLoaderPlugin } from './file-loader-plugin';\n\n/**\n * Options used in `ng-packagr` for writing flat bundle files.\n *\n * These options are passed through to rollup.\n */\nexport interface RollupOptions {\n moduleName: string;\n entry: string;\n entryName: string;\n dir: string;\n sourceRoot: string;\n cache?: RollupCache;\n cacheDirectory?: string | false;\n fileCache: OutputFileCache;\n cacheKey: string;\n}\n\nlet rollup: typeof import('rollup') | undefined;\n\n/** Runs rollup over the given entry file, writes a bundle file. */\nexport async function rollupBundleFile(\n opts: RollupOptions,\n): Promise<{ cache: RollupCache; files: (OutputChunk | OutputAsset)[] }> {\n await ensureRollup();\n\n log.debug(`rollup (v${rollup.VERSION}) ${opts.entry} to ${opts.dir}`);\n\n const cacheDirectory = opts.cacheDirectory;\n\n // Create the bundle\n const bundle = await rollup.rollup({\n context: 'this',\n external: moduleId => isExternalDependency(moduleId),\n cache: opts.cache ?? (cacheDirectory ? await readCacheEntry(cacheDirectory, opts.cacheKey) : undefined),\n input: opts.entry,\n plugins: [nodeResolve(), rollupJson(), fileLoaderPlugin(opts.fileCache)],\n onwarn: warning => {\n switch (warning.code) {\n case 'CIRCULAR_DEPENDENCY':\n case 'UNUSED_EXTERNAL_IMPORT':\n case 'THIS_IS_UNDEFINED':\n break;\n\n default:\n log.warn(warning.message);\n break;\n }\n },\n preserveSymlinks: true,\n // Disable treeshaking when generating bundles\n // see: https://github.com/angular/angular/pull/32069\n treeshake: false,\n });\n\n // Output the bundle to disk\n const output = await bundle.write({\n name: opts.moduleName,\n format: 'es',\n dir: opts.dir,\n inlineDynamicImports: false,\n chunkFileNames: opts.entryName + '-[name]-[hash].mjs',\n entryFileNames: opts.entryName + '.mjs',\n banner: '',\n sourcemap: true,\n });\n\n if (cacheDirectory) {\n await saveCacheEntry(cacheDirectory, opts.cacheKey, JSON.stringify(bundle.cache));\n }\n\n // Close the bundle to let plugins clean up their external processes or services\n await bundle.close();\n\n return {\n files: output.output,\n cache: bundle.cache,\n };\n}\n\nasync function ensureRollup(): Promise<void> {\n if (rollup) {\n return;\n }\n\n try {\n rollup = await import('rollup');\n log.debug(`rollup using native version.`);\n } catch {\n rollup = await import('@rollup/wasm-node');\n log.debug(`rollup using wasm version.`);\n }\n}\n\nfunction isExternalDependency(moduleId: string): boolean {\n // more information about why we don't check for 'node_modules' path\n // https://github.com/rollup/rollup-plugin-node-resolve/issues/110#issuecomment-350353632\n if (moduleId.startsWith('.') || moduleId.startsWith('/') || path.isAbsolute(moduleId)) {\n // if it's either 'absolute', marked to embed, starts with a '.' or '/' or is the umd bundle and is tslib\n return false;\n }\n\n return true;\n}\n"]}
|
|
@@ -5,35 +5,94 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.writeBundlesTransform = void 0;
|
|
7
7
|
const ora_1 = __importDefault(require("ora"));
|
|
8
|
-
const
|
|
8
|
+
const path_1 = require("path");
|
|
9
|
+
const rollup_1 = require("../../flatten/rollup");
|
|
9
10
|
const transform_1 = require("../../graph/transform");
|
|
11
|
+
const cache_1 = require("../../utils/cache");
|
|
12
|
+
const fs_1 = require("../../utils/fs");
|
|
10
13
|
const nodes_1 = require("../nodes");
|
|
11
14
|
const writeBundlesTransform = (options) => (0, transform_1.transformFromPromise)(async (graph) => {
|
|
12
15
|
const entryPoint = graph.find((0, nodes_1.isEntryPointInProgress)());
|
|
13
|
-
const { destinationFiles, entryPoint: ngEntryPoint } = entryPoint.data;
|
|
16
|
+
const { destinationFiles, entryPoint: ngEntryPoint, tsConfig } = entryPoint.data;
|
|
14
17
|
const cache = entryPoint.cache;
|
|
15
18
|
const { fesm2022Dir, esm2022 } = destinationFiles;
|
|
16
19
|
const spinner = (0, ora_1.default)({
|
|
17
20
|
hideCursor: false,
|
|
18
21
|
discardStdin: false,
|
|
19
22
|
});
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
+
const key = await (0, cache_1.generateKey)(ngEntryPoint.moduleId, esm2022, fesm2022Dir, tsConfig.options.compilationMode);
|
|
24
|
+
const hash = await (0, cache_1.generateKey)([...cache.outputCache.values()].map(({ version }) => version).join(':'));
|
|
25
|
+
const cacheDirectory = options.cacheEnabled && options.cacheDirectory;
|
|
26
|
+
if (cacheDirectory) {
|
|
27
|
+
const cacheResult = await (0, cache_1.readCacheEntry)(options.cacheDirectory, key);
|
|
28
|
+
let writing = false;
|
|
29
|
+
if ((cacheResult === null || cacheResult === void 0 ? void 0 : cacheResult.hash) === hash) {
|
|
30
|
+
try {
|
|
31
|
+
for (const file of cacheResult.fesm2022) {
|
|
32
|
+
const filePath = (0, path_1.join)(fesm2022Dir, file.fileName);
|
|
33
|
+
if (options.watch && await (0, fs_1.exists)(filePath)) {
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
if (!writing) {
|
|
37
|
+
writing = true;
|
|
38
|
+
spinner.start('Writing FESM bundles');
|
|
39
|
+
await (0, fs_1.mkdir)(fesm2022Dir, { recursive: true });
|
|
40
|
+
}
|
|
41
|
+
await (0, fs_1.writeFile)(filePath, file.type === 'asset' ? file.source : file.code);
|
|
42
|
+
}
|
|
43
|
+
if (writing) {
|
|
44
|
+
spinner.succeed('Writing FESM bundles');
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
if (!writing) {
|
|
49
|
+
spinner.start('Writing FESM bundles');
|
|
50
|
+
}
|
|
51
|
+
spinner.fail();
|
|
52
|
+
throw error;
|
|
53
|
+
}
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
async function generateFESM(rollupCache, dir) {
|
|
58
|
+
const { cache: rollupFESMCache, files } = await (0, rollup_1.rollupBundleFile)({
|
|
59
|
+
sourceRoot: tsConfig.options.sourceRoot,
|
|
23
60
|
entry: esm2022,
|
|
24
|
-
outdir: fesm2022Dir,
|
|
25
61
|
entryName: ngEntryPoint.flatModuleFile,
|
|
26
62
|
moduleName: ngEntryPoint.moduleId,
|
|
27
|
-
|
|
63
|
+
dir,
|
|
64
|
+
cache: rollupCache,
|
|
65
|
+
cacheDirectory,
|
|
28
66
|
fileCache: cache.outputCache,
|
|
67
|
+
cacheKey: await (0, cache_1.generateKey)(esm2022, dir, ngEntryPoint.moduleId, tsConfig.options.compilationMode),
|
|
29
68
|
});
|
|
30
|
-
|
|
69
|
+
return {
|
|
70
|
+
/** The map contents are in an asset file type, which makes storing the map in the cache as redudant. */
|
|
71
|
+
files: files.map(f => {
|
|
72
|
+
if (f.type === 'chunk') {
|
|
73
|
+
f.map = null;
|
|
74
|
+
}
|
|
75
|
+
return f;
|
|
76
|
+
}),
|
|
77
|
+
rollupCache: options.watch ? rollupFESMCache : undefined,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
const fesmCache = {
|
|
81
|
+
hash,
|
|
82
|
+
};
|
|
83
|
+
try {
|
|
84
|
+
const { rollupCache, files } = await generateFESM(cache.rollupFESM2022Cache, fesm2022Dir);
|
|
85
|
+
cache.rollupFESM2022Cache = rollupCache;
|
|
86
|
+
fesmCache.fesm2022 = files;
|
|
31
87
|
spinner.succeed(`Generating FESM bundles`);
|
|
32
88
|
}
|
|
33
89
|
catch (error) {
|
|
34
90
|
spinner.fail();
|
|
35
91
|
throw error;
|
|
36
92
|
}
|
|
93
|
+
if (cacheDirectory) {
|
|
94
|
+
await (0, cache_1.saveCacheEntry)(cacheDirectory, key, JSON.stringify(fesmCache));
|
|
95
|
+
}
|
|
37
96
|
});
|
|
38
97
|
exports.writeBundlesTransform = writeBundlesTransform;
|
|
39
98
|
//# sourceMappingURL=write-bundles.transform.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"write-bundles.transform.js","sourceRoot":"","sources":["../../../../src/lib/ng-package/entry-point/write-bundles.transform.ts"],"names":[],"mappings":";;;;;;AAAA,8CAAsB;AACtB,
|
|
1
|
+
{"version":3,"file":"write-bundles.transform.js","sourceRoot":"","sources":["../../../../src/lib/ng-package/entry-point/write-bundles.transform.ts"],"names":[],"mappings":";;;;;;AAAA,8CAAsB;AACtB,+BAA4B;AAE5B,iDAAwD;AACxD,qDAA6D;AAC7D,6CAAgF;AAChF,uCAA0D;AAC1D,oCAAkE;AAQ3D,MAAM,qBAAqB,GAAG,CAAC,OAAyB,EAAE,EAAE,CACjE,IAAA,gCAAoB,EAAC,KAAK,EAAC,KAAK,EAAC,EAAE;IACjC,MAAM,UAAU,GAAmB,KAAK,CAAC,IAAI,CAAC,IAAA,8BAAsB,GAAE,CAAC,CAAC;IACxE,MAAM,EAAE,gBAAgB,EAAE,UAAU,EAAE,YAAY,EAAE,QAAQ,EAAE,GAAG,UAAU,CAAC,IAAI,CAAC;IACjF,MAAM,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC;IAC/B,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,GAAG,gBAAgB,CAAC;IAElD,MAAM,OAAO,GAAG,IAAA,aAAG,EAAC;QAClB,UAAU,EAAE,KAAK;QACjB,YAAY,EAAE,KAAK;KACpB,CAAC,CAAC;IAEH,MAAM,GAAG,GAAG,MAAM,IAAA,mBAAW,EAAC,YAAY,CAAC,QAAQ,EAAE,OAAO,EAAE,WAAW,EAAE,QAAQ,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC;IAC7G,MAAM,IAAI,GAAG,MAAM,IAAA,mBAAW,EAAC,CAAC,GAAG,KAAK,CAAC,WAAW,CAA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AAmB,EAAE,WAAW,CAAC,CAAC;QAE1F,KAAK,CAAC,mBAAmB,GAAG,WAAW,CAAC;QACxC,SAAS,CAAC,QAAQ,GAAG,KAAK,CAAC;QAE3B,OAAO,CAAC,OAAO,CAAC,yBAAyB,CAAC,CAAC;IAC7C,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,IAAI,EAAE,CAAC;QACf,MAAM,KAAK,CAAC;IACd,CAAC;IAED,IAAI,cAAc,EAAE,CAAC;QACnB,MAAM,IAAA,sBAAc,EAAC,cAAc,EAAE,GAAG,EAAE,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC;IACvE,CAAC;AACH,CAAC,CAAC,CAAC;AApGQ,QAAA,qBAAqB,yBAoG7B","sourcesContent":["import ora from 'ora';\nimport { join } from 'path';\nimport type { OutputAsset, OutputChunk, RollupCache } from 'rollup';\nimport { rollupBundleFile } from '../../flatten/rollup';\nimport { transformFromPromise } from '../../graph/transform';\nimport { generateKey, readCacheEntry, saveCacheEntry } from '../../utils/cache';\nimport { exists, mkdir, writeFile } from '../../utils/fs';\nimport { EntryPointNode, isEntryPointInProgress } from '../nodes';\nimport { NgPackagrOptions } from '../options.di';\n\ninterface BundlesCache {\n hash: string;\n fesm2022: (OutputChunk | OutputAsset)[];\n}\n\nexport const writeBundlesTransform = (options: NgPackagrOptions) =>\n transformFromPromise(async graph => {\n const entryPoint: EntryPointNode = graph.find(isEntryPointInProgress());\n const { destinationFiles, entryPoint: ngEntryPoint, tsConfig } = entryPoint.data;\n const cache = entryPoint.cache;\n const { fesm2022Dir, esm2022 } = destinationFiles;\n\n const spinner = ora({\n hideCursor: false,\n discardStdin: false,\n });\n\n const key = await generateKey(ngEntryPoint.moduleId, esm2022, fesm2022Dir, tsConfig.options.compilationMode);\n const hash = await generateKey([...cache.outputCache.values()].map(({ version }) => version).join(':'));\n const cacheDirectory = options.cacheEnabled && options.cacheDirectory;\n if (cacheDirectory) {\n const cacheResult: BundlesCache = await readCacheEntry(options.cacheDirectory, key);\n let writing = false;\n\n if (cacheResult?.hash === hash) {\n try {\n for (const file of cacheResult.fesm2022) {\n const filePath = join(fesm2022Dir, file.fileName);\n if (options.watch && await exists(filePath)) {\n continue;\n }\n\n if (!writing) {\n writing = true;\n spinner.start('Writing FESM bundles');\n await mkdir(fesm2022Dir, { recursive: true });\n }\n\n await writeFile(filePath, file.type === 'asset' ? file.source : file.code);\n }\n\n if (writing) {\n spinner.succeed('Writing FESM bundles');\n }\n } catch (error) {\n if (!writing) {\n spinner.start('Writing FESM bundles');\n }\n\n spinner.fail();\n throw error;\n }\n\n return;\n }\n }\n\n async function generateFESM(\n rollupCache: RollupCache,\n dir: string,\n ): Promise<{ files: (OutputChunk | OutputAsset)[]; rollupCache: RollupCache }> {\n const { cache: rollupFESMCache, files } = await rollupBundleFile({\n sourceRoot: tsConfig.options.sourceRoot,\n entry: esm2022,\n entryName: ngEntryPoint.flatModuleFile,\n moduleName: ngEntryPoint.moduleId,\n dir,\n cache: rollupCache,\n cacheDirectory,\n fileCache: cache.outputCache,\n cacheKey: await generateKey(esm2022, dir, ngEntryPoint.moduleId, tsConfig.options.compilationMode),\n });\n\n return {\n /** The map contents are in an asset file type, which makes storing the map in the cache as redudant. */\n files: files.map(f => {\n if (f.type === 'chunk') {\n f.map = null;\n }\n\n return f;\n }),\n rollupCache: options.watch ? rollupFESMCache : undefined,\n };\n }\n\n const fesmCache: Partial<BundlesCache> = {\n hash,\n };\n\n try {\n const { rollupCache, files } = await generateFESM(cache.rollupFESM2022Cache, fesm2022Dir);\n\n cache.rollupFESM2022Cache = rollupCache;\n fesmCache.fesm2022 = files;\n\n spinner.succeed(`Generating FESM bundles`);\n } catch (error) {\n spinner.fail();\n throw error;\n }\n\n if (cacheDirectory) {\n await saveCacheEntry(cacheDirectory, key, JSON.stringify(fesmCache));\n }\n });\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { NgtscProgram, ParsedConfiguration, Program } from '@angular/compiler-cli';
|
|
2
|
-
import {
|
|
2
|
+
import type { RollupCache } from 'rollup';
|
|
3
3
|
import ts from 'typescript';
|
|
4
4
|
import { FileCache } from '../file-system/file-cache';
|
|
5
5
|
import { ComplexPredicate } from '../graph/build-graph';
|
|
@@ -37,7 +37,7 @@ export declare class EntryPointNode extends Node {
|
|
|
37
37
|
sourcesFileCache: FileCache;
|
|
38
38
|
analysesSourcesFileCache: FileCache;
|
|
39
39
|
moduleResolutionCache: ts.ModuleResolutionCache;
|
|
40
|
-
|
|
40
|
+
rollupFESM2022Cache?: RollupCache;
|
|
41
41
|
stylesheetProcessor?: StylesheetProcessor;
|
|
42
42
|
oldNgtscProgram?: NgtscProgram;
|
|
43
43
|
oldBuilder?: ts.EmitAndSemanticDiagnosticsBuilderProgram;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nodes.js","sourceRoot":"","sources":["../../../src/lib/ng-package/nodes.ts"],"names":[],"mappings":";;;;;;AAEA,4DAA4B;AAC5B,0DAAsD;AAEtD,wCAAqC;AACrC,4CAA4D;AAK/C,QAAA,eAAe,GAAG,wBAAwB,CAAC;AAC3C,QAAA,mBAAmB,GAAG,4BAA4B,CAAC;AAEhE,oDAAoD;AACvC,QAAA,iBAAiB,GAAG,SAAS,CAAC;AAE3C,kCAAkC;AACrB,QAAA,eAAe,GAAG,OAAO,CAAC;AAEvC,SAAgB,YAAY,CAAC,IAAU;IACrC,OAAO,IAAI,CAAC,IAAI,KAAK,2BAAmB,CAAC;AAC3C,CAAC;AAFD,oCAEC;AAED,SAAgB,SAAS,CAAC,IAAU;IAClC,OAAO,IAAI,CAAC,IAAI,KAAK,uBAAe,CAAC;AACvC,CAAC;AAFD,8BAEC;AAED,SAAgB,YAAY;IAC1B,OAAO,IAAA,WAAE,EAAC,YAAY,CAAC,CAAC;AAC1B,CAAC;AAFD,oCAEC;AAED,SAAgB,sBAAsB;IACpC,OAAO,IAAA,WAAE,EAAC,YAAY,CAAC,CA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BAA2B,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;SAC7E,CAAC;IACJ,CAAC;CAAA;AARD,kCAQC","sourcesContent":["import type { NgtscProgram, ParsedConfiguration, Program } from '@angular/compiler-cli';\nimport {
|
|
1
|
+
{"version":3,"file":"nodes.js","sourceRoot":"","sources":["../../../src/lib/ng-package/nodes.ts"],"names":[],"mappings":";;;;;;AAEA,4DAA4B;AAC5B,0DAAsD;AAEtD,wCAAqC;AACrC,4CAA4D;AAK/C,QAAA,eAAe,GAAG,wBAAwB,CAAC;AAC3C,QAAA,mBAAmB,GAAG,4BAA4B,CAAC;AAEhE,oDAAoD;AACvC,QAAA,iBAAiB,GAAG,SAAS,CAAC;AAE3C,kCAAkC;AACrB,QAAA,eAAe,GAAG,OAAO,CAAC;AAEvC,SAAgB,YAAY,CAAC,IAAU;IACrC,OAAO,IAAI,CAAC,IAAI,KAAK,2BAAmB,CAAC;AAC3C,CAAC;AAFD,oCAEC;AAED,SAAgB,SAAS,CAAC,IAAU;IAClC,OAAO,IAAI,CAAC,IAAI,KAAK,uBAAe,CAAC;AACvC,CAAC;AAFD,8BAEC;AAED,SAAgB,YAAY;IAC1B,OAAO,IAAA,WAAE,EAAC,YAAY,CAAC,CAAC;AAC1B,CAAC;AAFD,oCAEC;AAED,SAAgB,sBAAsB;IACpC,OAAO,IAAA,WAAE,EAAC,YAAY,CAAC,CAAC,GAAG,CAAC,qBAAY,CAAC,CAAC;AAC5C,CAAC;AAFD,wDAEC;AAED,SAAgB,iBAAiB;IAC/B,OAAO,IAAA,WAAE,EAAC,YAAY,CAAC,CAAC,GAAG,CAAC,gBAAO,CAAC,CAAC;AACvC,CAAC;AAFD,8CAEC;AAED,SAAgB,SAAS,CAAC,KAAa;IACrC,OAAO,KAAK,CAAC,UAAU,CAAC,yBAAiB,CAAC,CAAC;AAC7C,CAAC;AAFD,8BAEC;AAED,SAAgB,OAAO,CAAC,IAAY;IAClC,OAAO,GAAG,yBAAiB,GAAG,IAAI,EAAE,CAAC;AACvC,CAAC;AAFD,0BAEC;AAED,SAAgB,WAAW,CAAC,GAAW;IACrC,IAAI,GAAG,CAAC,UAAU,CAAC,yBAAiB,CAAC,EAAE,CAAC;QACtC,OAAO,GAAG,CAAC,SAAS,CAAC,yBAAiB,CAAC,MAAM,CAAC,CAAC;IACjD,CAAC;AACH,CAAC;AAJD,kCAIC;AAED,SAAgB,KAAK,CAAC,IAAY;IAChC,OAAO,GAAG,uBAAe,GAAG,IAAI,EAAE,CAAC;AACrC,CAAC;AAFD,sBAEC;AAID,MAAa,cAAe,SAAQ,WAAI;IAGtC,YACkB,GAAW,EAC3B,gBAA2B,EAC3B,qBAA+C;QAE/C,KAAK,CAAC,GAAG,CAAC,CAAC;QAJK,QAAG,GAAH,GAAG,CAAQ;QAHpB,SAAI,GAAG,2BAAmB,CAAC;QASlC,IAAI,CAAC,KAAK,GAAG;YACX,gBAAgB;YAChB,wBAAwB,EAAE,IAAI,sBAAS,EAAE;YACzC,qBAAqB;YACrB,WAAW,EAAE,IAAI,GAAG,EAAE;SACvB,CAAC;IACJ,CAAC;CAmBF;AAnCD,wCAmCC;AAED,MAAa,WAAY,SAAQ,WAAI;IAArC;;QACW,SAAI,GAAG,uBAAe,CAAC;QAGhC,UAAK,GAAG;YACN,gBAAgB,EAAE,IAAI,sBAAS,EAAE;YACjC,qBAAqB,EAAE,oBAAE,CAAC,2BAA2B,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;SAC7E,CAAC;IACJ,CAAC;CAAA;AARD,kCAQC","sourcesContent":["import type { NgtscProgram, ParsedConfiguration, Program } from '@angular/compiler-cli';\nimport type { RollupCache } from 'rollup';\nimport ts from 'typescript';\nimport { FileCache } from '../file-system/file-cache';\nimport { ComplexPredicate } from '../graph/build-graph';\nimport { Node } from '../graph/node';\nimport { by, isDirty, isInProgress } from '../graph/select';\nimport { StylesheetProcessor } from '../styles/stylesheet-processor';\nimport { DestinationFiles, NgEntryPoint } from './entry-point/entry-point';\nimport { NgPackage } from './package';\n\nexport const TYPE_NG_PACKAGE = 'application/ng-package';\nexport const TYPE_NG_ENTRY_POINT = 'application/ng-entry-point';\n\n/** A node that can be read through the `fs` api. */\nexport const URL_PROTOCOL_FILE = 'file://';\n\n/** A node specific to angular. */\nexport const URL_PROTOCOL_NG = 'ng://';\n\nexport function isEntryPoint(node: Node): node is EntryPointNode {\n return node.type === TYPE_NG_ENTRY_POINT;\n}\n\nexport function isPackage(node: Node): node is PackageNode {\n return node.type === TYPE_NG_PACKAGE;\n}\n\nexport function byEntryPoint(): ComplexPredicate<EntryPointNode> {\n return by(isEntryPoint);\n}\n\nexport function isEntryPointInProgress(): ComplexPredicate<EntryPointNode> {\n return by(isEntryPoint).and(isInProgress);\n}\n\nexport function isEntryPointDirty(): ComplexPredicate<EntryPointNode> {\n return by(isEntryPoint).and(isDirty);\n}\n\nexport function isFileUrl(value: string): boolean {\n return value.startsWith(URL_PROTOCOL_FILE);\n}\n\nexport function fileUrl(path: string): string {\n return `${URL_PROTOCOL_FILE}${path}`;\n}\n\nexport function fileUrlPath(url: string): string {\n if (url.startsWith(URL_PROTOCOL_FILE)) {\n return url.substring(URL_PROTOCOL_FILE.length);\n }\n}\n\nexport function ngUrl(path: string): string {\n return `${URL_PROTOCOL_NG}${path}`;\n}\n\nexport type OutputFileCache = Map<string, { version?: string; content: string; map?: any }>;\n\nexport class EntryPointNode extends Node {\n readonly type = TYPE_NG_ENTRY_POINT;\n\n constructor(\n public readonly url: string,\n sourcesFileCache: FileCache,\n moduleResolutionCache: ts.ModuleResolutionCache,\n ) {\n super(url);\n\n this.cache = {\n sourcesFileCache,\n analysesSourcesFileCache: new FileCache(),\n moduleResolutionCache,\n outputCache: new Map(),\n };\n }\n\n cache: {\n outputCache: OutputFileCache;\n oldPrograms?: Record<ts.ScriptTarget | 'analysis', Program | ts.Program>;\n sourcesFileCache: FileCache;\n analysesSourcesFileCache: FileCache;\n moduleResolutionCache: ts.ModuleResolutionCache;\n rollupFESM2022Cache?: RollupCache;\n stylesheetProcessor?: StylesheetProcessor;\n oldNgtscProgram?: NgtscProgram;\n oldBuilder?: ts.EmitAndSemanticDiagnosticsBuilderProgram;\n };\n\n data: {\n destinationFiles: DestinationFiles;\n entryPoint: NgEntryPoint;\n tsConfig?: ParsedConfiguration;\n };\n}\n\nexport class PackageNode extends Node {\n readonly type = TYPE_NG_PACKAGE;\n data: NgPackage;\n\n cache = {\n sourcesFileCache: new FileCache(),\n moduleResolutionCache: ts.createModuleResolutionCache(process.cwd(), s => s),\n };\n}\n"]}
|
|
@@ -85,11 +85,10 @@ const packageTransformFactory = (project, options, initTsConfigTransform, analys
|
|
|
85
85
|
initTsConfigTransform,
|
|
86
86
|
// perform build
|
|
87
87
|
buildTransform, (0, rxjs_1.finalize)(() => {
|
|
88
|
-
var _a
|
|
88
|
+
var _a;
|
|
89
89
|
for (const node of ngPkg.dependents) {
|
|
90
90
|
if (node instanceof nodes_1.EntryPointNode) {
|
|
91
91
|
(_a = node.cache.stylesheetProcessor) === null || _a === void 0 ? void 0 : _a.destroy();
|
|
92
|
-
void ((_b = node.cache.esbuildBuildContext) === null || _b === void 0 ? void 0 : _b.dispose());
|
|
93
92
|
}
|
|
94
93
|
}
|
|
95
94
|
}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"package.transform.js","sourceRoot":"","sources":["../../../src/lib/ng-package/package.transform.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uDAA4C;AAC5C,+BAiBc;AACd,8DAA8D;AAE9D,wCAA2E;AAE3E,0CAAwC;AACxC,oCAAoC;AACpC,kDAAoC;AACpC,wCAA+C;AAC/C,2DAAuD;AACvD,mCASiB;AAGjB;;;;;;;;;;;;;;;GAeG;AACI,MAAM,uBAAuB,GAClC,CACE,OAAe,EACf,OAAyB,EACzB,qBAAgC,EAChC,uBAAkC,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AAC,EAChF,IAAA,gBAAS,EAAC,EAAE,CAAC,EAAE,CACb,IAAA,SAAY,EAAC,EAAE,CAAC,CAAC,IAAI;IACnB,wCAAwC;IACxC,IAAA,UAAG,EAAC,UAAU,CAAC,EAAE,CAAC,CAAC,UAAU,CAAC,KAAK,GAAG,wBAAiB,CAAC,CAAC,EACzD,IAAA,UAAG,EAAC,GAAG,EAAE,CAAC,KAAK,CAAC,EAChB,WAAW,CACZ,CACF,EACD,IAAA,eAAQ,EAAC,CAAC,CAAC,EAAE,4EAA4E;IACzF,IAAA,qBAAc,EAAC,KAAK,CAAC,CACtB,CAAC;AACJ,CAAC,CAAC,CACH,CAAC","sourcesContent":["import { DepGraph } from 'dependency-graph';\nimport {\n NEVER,\n Observable,\n catchError,\n concatMap,\n debounceTime,\n defaultIfEmpty,\n filter,\n finalize,\n from,\n map,\n of as observableOf,\n pipe,\n startWith,\n switchMap,\n takeLast,\n tap,\n} from 'rxjs';\nimport { createFileWatch } from '../file-system/file-watcher';\nimport { BuildGraph } from '../graph/build-graph';\nimport { STATE_DIRTY, STATE_DONE, STATE_IN_PROGRESS } from '../graph/node';\nimport { Transform } from '../graph/transform';\nimport { colors } from '../utils/color';\nimport { rmdir } from '../utils/fs';\nimport * as log from '../utils/log';\nimport { ensureUnixPath } from '../utils/path';\nimport { discoverPackages } from './discover-packages';\nimport {\n EntryPointNode,\n PackageNode,\n byEntryPoint,\n fileUrl,\n fileUrlPath,\n isEntryPoint,\n isPackage,\n ngUrl,\n} from './nodes';\nimport { NgPackagrOptions } from './options.di';\n\n/**\n * A transformation for building an npm package:\n *\n * - discoverPackages\n * - options\n * - initTsConfig\n * - analyzeTsSources (thereby extracting template and stylesheet files)\n * - for each entry point\n * - run the entryPontTransform\n *\n * @param project Project token, reference to `ng-package.json`\n * @param options ng-packagr options\n * @param initTsConfigTransform Transformation initializing the tsconfig of each entry point.\n * @param analyseSourcesTransform Transformation analyzing the typescript source files of each entry point.\n * @param entryPointTransform Transformation for asset rendering and compilation of a single entry point.\n */\nexport const packageTransformFactory =\n (\n project: string,\n options: NgPackagrOptions,\n initTsConfigTransform: Transform,\n analyseSourcesTransform: Transform,\n entryPointTransform: Transform,\n ) =>\n (source$: Observable<BuildGraph>): Observable<BuildGraph> => {\n log.info(`Building Angular Package`);\n\n const buildTransform = options.watch\n ? watchTransformFactory(project, options, analyseSourcesTransform, entryPointTransform)\n : buildTransformFactory(project, analyseSourcesTransform, entryPointTransform);\n\n const pkgUri = ngUrl(project);\n const ngPkg = new PackageNode(pkgUri);\n\n return source$.pipe(\n // Discover packages and entry points\n // Clean the primary dest folder (should clean all secondary sub-directory, as well)\n switchMap(async graph => {\n ngPkg.data = await discoverPackages({ project });\n\n graph.put(ngPkg);\n const { dest, deleteDestPath } = ngPkg.data;\n\n if (deleteDestPath) {\n try {\n await rmdir(dest, { recursive: true });\n } catch {}\n }\n\n const entryPoints = [ngPkg.data.primary, ...ngPkg.data.secondaries].map(entryPoint => {\n const { destinationFiles, moduleId } = entryPoint;\n const node = new EntryPointNode(\n ngUrl(moduleId),\n ngPkg.cache.sourcesFileCache,\n ngPkg.cache.moduleResolutionCache,\n );\n node.data = { entryPoint, destinationFiles };\n node.state = 'dirty';\n ngPkg.dependsOn(node);\n\n return node;\n });\n\n // Add entry points to graph\n return graph.put(entryPoints);\n }),\n // Initialize the tsconfig for each entry point\n initTsConfigTransform,\n // perform build\n buildTransform,\n finalize(() => {\n for (const node of ngPkg.dependents) {\n if (node instanceof EntryPointNode) {\n node.cache.stylesheetProcessor?.destroy();\n void node.cache.esbuildBuildContext?.dispose();\n }\n }\n }),\n );\n };\n\nconst watchTransformFactory =\n (project: string, options: NgPackagrOptions, analyseSourcesTransform: Transform, entryPointTransform: Transform) =>\n (source$: Observable<BuildGraph>): Observable<BuildGraph> => {\n const CompleteWaitingForFileChange = '\\nCompilation complete. Watching for file changes...';\n const FileChangeDetected = '\\nFile change detected. Starting incremental compilation...';\n const FailedWaitingForFileChange = '\\nCompilation failed. Watching for file changes...';\n\n return source$.pipe(\n switchMap(graph => {\n const { data, cache } = graph.find(isPackage);\n const { onFileChange, watcher } = createFileWatch([], [data.dest], options.poll);\n graph.watcher = watcher;\n\n return onFileChange.pipe(\n tap(fileChange => {\n const { filePath } = fileChange;\n const { sourcesFileCache } = cache;\n const cachedSourceFile = sourcesFileCache.get(filePath);\n const { declarationFileName } = cachedSourceFile || {};\n const uriToClean = [filePath, declarationFileName].map(x => fileUrl(ensureUnixPath(x)));\n const nodesToClean = graph.filter(node => uriToClean.some(uri => uri === node.url));\n\n if (!cachedSourceFile) {\n if (!nodesToClean) {\n return;\n }\n }\n\n const allNodesToClean = [\n ...nodesToClean,\n // if a non ts file changes we need to clean up its direct dependees\n // this is mainly done for resources such as html and css\n ...nodesToClean.filter(node => !node.url.endsWith('.ts')).flatMap(node => [...node.dependees]),\n ];\n\n // delete node that changes\n for (const { url } of allNodesToClean) {\n sourcesFileCache.delete(fileUrlPath(url));\n }\n\n for (const entryPoint of graph.filter(isEntryPoint)) {\n const isDirty = [...allNodesToClean].some(dependent => entryPoint.dependents.has(dependent));\n if (isDirty) {\n entryPoint.state = STATE_DIRTY;\n\n uriToClean.forEach(url => {\n entryPoint.cache.analysesSourcesFileCache.delete(fileUrlPath(url));\n });\n }\n }\n }),\n debounceTime(200),\n tap(() => log.msg(FileChangeDetected)),\n startWith(undefined),\n map(() => graph),\n );\n }),\n switchMap(graph => {\n return observableOf(graph).pipe(\n buildTransformFactory(project, analyseSourcesTransform, entryPointTransform),\n tap(() => log.msg(CompleteWaitingForFileChange)),\n catchError(error => {\n log.error(error);\n log.msg(FailedWaitingForFileChange);\n\n return NEVER;\n }),\n );\n }),\n );\n };\n\nconst buildTransformFactory =\n (project: string, analyseSourcesTransform: Transform, entryPointTransform: Transform) =>\n (source$: Observable<BuildGraph>): Observable<BuildGraph> => {\n const startTime = Date.now();\n\n const pkgUri = ngUrl(project);\n\n return source$.pipe(\n // Analyse dependencies and external resources for each entry point\n analyseSourcesTransform,\n // Next, run through the entry point transformation (assets rendering, code compilation)\n scheduleEntryPoints(entryPointTransform),\n tap(graph => {\n const ngPkg = graph.get(pkgUri);\n log.success('\\n------------------------------------------------------------------------------');\n log.success(`Built Angular Package\n - from: ${ngPkg.data.src}\n - to: ${ngPkg.data.dest}`);\n log.success('------------------------------------------------------------------------------');\n const b = colors.bold;\n const w = colors.white;\n log.msg(w(`\\nBuild at: ${b(new Date().toISOString())} - Time: ${b('' + (Date.now() - startTime))}ms\\n`));\n }),\n );\n };\n\nconst scheduleEntryPoints = (epTransform: Transform): Transform =>\n pipe(\n concatMap(graph => {\n // Calculate node/dependency depth and determine build order\n const depGraph = new DepGraph({ circular: false });\n const entryPoints: EntryPointNode[] = graph.filter(isEntryPoint);\n\n for (const entryPoint of entryPoints) {\n // Remove `ng://` prefix for better error messages\n const from = entryPoint.url.substring(5);\n depGraph.addNode(from);\n\n for (const { url } of entryPoint.filter(isEntryPoint)) {\n const to = url.substring(5);\n depGraph.addNode(to);\n depGraph.addDependency(from, to);\n }\n }\n\n // The array index is the depth.\n const groups = depGraph.overallOrder().map(ngUrl);\n\n // Build entry points with lower depth values first.\n return from(groups).pipe(\n map((epUrl: string): EntryPointNode => graph.find(byEntryPoint().and(ep => ep.url === epUrl))),\n filter((entryPoint: EntryPointNode): boolean => entryPoint.state !== STATE_DONE),\n concatMap(ep =>\n observableOf(ep).pipe(\n // Mark the entry point as 'in-progress'\n tap(entryPoint => (entryPoint.state = STATE_IN_PROGRESS)),\n map(() => graph),\n epTransform,\n ),\n ),\n takeLast(1), // don't use last as sometimes it this will cause 'no elements in sequence',\n defaultIfEmpty(graph),\n );\n }),\n );\n"]}
|
|
1
|
+
{"version":3,"file":"package.transform.js","sourceRoot":"","sources":["../../../src/lib/ng-package/package.transform.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uDAA4C;AAC5C,+BAiBc;AACd,8DAA8D;AAE9D,wCAA2E;AAE3E,0CAAwC;AACxC,oCAA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AA,aAAM,EAAC,CAAC,UAA0B,EAAW,EAAE,CAAC,UAAU,CAAC,KAAK,KAAK,iBAAU,CAAC,EAChF,IAAA,gBAAS,EAAC,EAAE,CAAC,EAAE,CACb,IAAA,SAAY,EAAC,EAAE,CAAC,CAAC,IAAI;IACnB,wCAAwC;IACxC,IAAA,UAAG,EAAC,UAAU,CAAC,EAAE,CAAC,CAAC,UAAU,CAAC,KAAK,GAAG,wBAAiB,CAAC,CAAC,EACzD,IAAA,UAAG,EAAC,GAAG,EAAE,CAAC,KAAK,CAAC,EAChB,WAAW,CACZ,CACF,EACD,IAAA,eAAQ,EAAC,CAAC,CAAC,EAAE,4EAA4E;IACzF,IAAA,qBAAc,EAAC,KAAK,CAAC,CACtB,CAAC;AACJ,CAAC,CAAC,CACH,CAAC","sourcesContent":["import { DepGraph } from 'dependency-graph';\nimport {\n NEVER,\n Observable,\n catchError,\n concatMap,\n debounceTime,\n defaultIfEmpty,\n filter,\n finalize,\n from,\n map,\n of as observableOf,\n pipe,\n startWith,\n switchMap,\n takeLast,\n tap,\n} from 'rxjs';\nimport { createFileWatch } from '../file-system/file-watcher';\nimport { BuildGraph } from '../graph/build-graph';\nimport { STATE_DIRTY, STATE_DONE, STATE_IN_PROGRESS } from '../graph/node';\nimport { Transform } from '../graph/transform';\nimport { colors } from '../utils/color';\nimport { rmdir } from '../utils/fs';\nimport * as log from '../utils/log';\nimport { ensureUnixPath } from '../utils/path';\nimport { discoverPackages } from './discover-packages';\nimport {\n EntryPointNode,\n PackageNode,\n byEntryPoint,\n fileUrl,\n fileUrlPath,\n isEntryPoint,\n isPackage,\n ngUrl,\n} from './nodes';\nimport { NgPackagrOptions } from './options.di';\n\n/**\n * A transformation for building an npm package:\n *\n * - discoverPackages\n * - options\n * - initTsConfig\n * - analyzeTsSources (thereby extracting template and stylesheet files)\n * - for each entry point\n * - run the entryPontTransform\n *\n * @param project Project token, reference to `ng-package.json`\n * @param options ng-packagr options\n * @param initTsConfigTransform Transformation initializing the tsconfig of each entry point.\n * @param analyseSourcesTransform Transformation analyzing the typescript source files of each entry point.\n * @param entryPointTransform Transformation for asset rendering and compilation of a single entry point.\n */\nexport const packageTransformFactory =\n (\n project: string,\n options: NgPackagrOptions,\n initTsConfigTransform: Transform,\n analyseSourcesTransform: Transform,\n entryPointTransform: Transform,\n ) =>\n (source$: Observable<BuildGraph>): Observable<BuildGraph> => {\n log.info(`Building Angular Package`);\n\n const buildTransform = options.watch\n ? watchTransformFactory(project, options, analyseSourcesTransform, entryPointTransform)\n : buildTransformFactory(project, analyseSourcesTransform, entryPointTransform);\n\n const pkgUri = ngUrl(project);\n const ngPkg = new PackageNode(pkgUri);\n\n return source$.pipe(\n // Discover packages and entry points\n // Clean the primary dest folder (should clean all secondary sub-directory, as well)\n switchMap(async graph => {\n ngPkg.data = await discoverPackages({ project });\n\n graph.put(ngPkg);\n const { dest, deleteDestPath } = ngPkg.data;\n\n if (deleteDestPath) {\n try {\n await rmdir(dest, { recursive: true });\n } catch {}\n }\n\n const entryPoints = [ngPkg.data.primary, ...ngPkg.data.secondaries].map(entryPoint => {\n const { destinationFiles, moduleId } = entryPoint;\n const node = new EntryPointNode(\n ngUrl(moduleId),\n ngPkg.cache.sourcesFileCache,\n ngPkg.cache.moduleResolutionCache,\n );\n node.data = { entryPoint, destinationFiles };\n node.state = 'dirty';\n ngPkg.dependsOn(node);\n\n return node;\n });\n\n // Add entry points to graph\n return graph.put(entryPoints);\n }),\n // Initialize the tsconfig for each entry point\n initTsConfigTransform,\n // perform build\n buildTransform,\n finalize(() => {\n for (const node of ngPkg.dependents) {\n if (node instanceof EntryPointNode) {\n node.cache.stylesheetProcessor?.destroy();\n }\n }\n }),\n );\n };\n\nconst watchTransformFactory =\n (project: string, options: NgPackagrOptions, analyseSourcesTransform: Transform, entryPointTransform: Transform) =>\n (source$: Observable<BuildGraph>): Observable<BuildGraph> => {\n const CompleteWaitingForFileChange = '\\nCompilation complete. Watching for file changes...';\n const FileChangeDetected = '\\nFile change detected. Starting incremental compilation...';\n const FailedWaitingForFileChange = '\\nCompilation failed. Watching for file changes...';\n\n return source$.pipe(\n switchMap(graph => {\n const { data, cache } = graph.find(isPackage);\n const { onFileChange, watcher } = createFileWatch([], [data.dest], options.poll);\n graph.watcher = watcher;\n\n return onFileChange.pipe(\n tap(fileChange => {\n const { filePath } = fileChange;\n const { sourcesFileCache } = cache;\n const cachedSourceFile = sourcesFileCache.get(filePath);\n const { declarationFileName } = cachedSourceFile || {};\n const uriToClean = [filePath, declarationFileName].map(x => fileUrl(ensureUnixPath(x)));\n const nodesToClean = graph.filter(node => uriToClean.some(uri => uri === node.url));\n\n if (!cachedSourceFile) {\n if (!nodesToClean) {\n return;\n }\n }\n\n const allNodesToClean = [\n ...nodesToClean,\n // if a non ts file changes we need to clean up its direct dependees\n // this is mainly done for resources such as html and css\n ...nodesToClean.filter(node => !node.url.endsWith('.ts')).flatMap(node => [...node.dependees]),\n ];\n\n // delete node that changes\n for (const { url } of allNodesToClean) {\n sourcesFileCache.delete(fileUrlPath(url));\n }\n\n for (const entryPoint of graph.filter(isEntryPoint)) {\n const isDirty = [...allNodesToClean].some(dependent => entryPoint.dependents.has(dependent));\n if (isDirty) {\n entryPoint.state = STATE_DIRTY;\n\n uriToClean.forEach(url => {\n entryPoint.cache.analysesSourcesFileCache.delete(fileUrlPath(url));\n });\n }\n }\n }),\n debounceTime(200),\n tap(() => log.msg(FileChangeDetected)),\n startWith(undefined),\n map(() => graph),\n );\n }),\n switchMap(graph => {\n return observableOf(graph).pipe(\n buildTransformFactory(project, analyseSourcesTransform, entryPointTransform),\n tap(() => log.msg(CompleteWaitingForFileChange)),\n catchError(error => {\n log.error(error);\n log.msg(FailedWaitingForFileChange);\n\n return NEVER;\n }),\n );\n }),\n );\n };\n\nconst buildTransformFactory =\n (project: string, analyseSourcesTransform: Transform, entryPointTransform: Transform) =>\n (source$: Observable<BuildGraph>): Observable<BuildGraph> => {\n const startTime = Date.now();\n\n const pkgUri = ngUrl(project);\n\n return source$.pipe(\n // Analyse dependencies and external resources for each entry point\n analyseSourcesTransform,\n // Next, run through the entry point transformation (assets rendering, code compilation)\n scheduleEntryPoints(entryPointTransform),\n tap(graph => {\n const ngPkg = graph.get(pkgUri);\n log.success('\\n------------------------------------------------------------------------------');\n log.success(`Built Angular Package\n - from: ${ngPkg.data.src}\n - to: ${ngPkg.data.dest}`);\n log.success('------------------------------------------------------------------------------');\n const b = colors.bold;\n const w = colors.white;\n log.msg(w(`\\nBuild at: ${b(new Date().toISOString())} - Time: ${b('' + (Date.now() - startTime))}ms\\n`));\n }),\n );\n };\n\nconst scheduleEntryPoints = (epTransform: Transform): Transform =>\n pipe(\n concatMap(graph => {\n // Calculate node/dependency depth and determine build order\n const depGraph = new DepGraph({ circular: false });\n const entryPoints: EntryPointNode[] = graph.filter(isEntryPoint);\n\n for (const entryPoint of entryPoints) {\n // Remove `ng://` prefix for better error messages\n const from = entryPoint.url.substring(5);\n depGraph.addNode(from);\n\n for (const { url } of entryPoint.filter(isEntryPoint)) {\n const to = url.substring(5);\n depGraph.addNode(to);\n depGraph.addDependency(from, to);\n }\n }\n\n // The array index is the depth.\n const groups = depGraph.overallOrder().map(ngUrl);\n\n // Build entry points with lower depth values first.\n return from(groups).pipe(\n map((epUrl: string): EntryPointNode => graph.find(byEntryPoint().and(ep => ep.url === epUrl))),\n filter((entryPoint: EntryPointNode): boolean => entryPoint.state !== STATE_DONE),\n concatMap(ep =>\n observableOf(ep).pipe(\n // Mark the entry point as 'in-progress'\n tap(entryPoint => (entryPoint.state = STATE_IN_PROGRESS)),\n map(() => graph),\n epTransform,\n ),\n ),\n takeLast(1), // don't use last as sometimes it this will cause 'no elements in sequence',\n defaultIfEmpty(graph),\n );\n }),\n );\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ng-packagr",
|
|
3
|
-
"version": "18.0.0
|
|
3
|
+
"version": "18.0.0",
|
|
4
4
|
"description": "Compile and package Angular libraries in Angular Package Format (APF)",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"apf",
|
|
@@ -37,6 +37,9 @@
|
|
|
37
37
|
"main": "./public_api.js",
|
|
38
38
|
"typings": "./public_api.d.ts",
|
|
39
39
|
"dependencies": {
|
|
40
|
+
"@rollup/plugin-json": "^6.1.0",
|
|
41
|
+
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
42
|
+
"@rollup/wasm-node": "^4.18.0",
|
|
40
43
|
"ajv": "^8.12.0",
|
|
41
44
|
"ansi-colors": "^4.1.3",
|
|
42
45
|
"browserslist": "^4.22.1",
|
|
@@ -45,7 +48,7 @@
|
|
|
45
48
|
"commander": "^12.0.0",
|
|
46
49
|
"convert-source-map": "^2.0.0",
|
|
47
50
|
"dependency-graph": "^1.0.0",
|
|
48
|
-
"esbuild": "^0.
|
|
51
|
+
"esbuild": "^0.21.3",
|
|
49
52
|
"fast-glob": "^3.3.1",
|
|
50
53
|
"find-cache-dir": "^3.3.2",
|
|
51
54
|
"injection-js": "^2.4.0",
|
|
@@ -57,8 +60,11 @@
|
|
|
57
60
|
"rxjs": "^7.8.1",
|
|
58
61
|
"sass": "^1.69.5"
|
|
59
62
|
},
|
|
63
|
+
"optionalDependencies": {
|
|
64
|
+
"rollup": "^4.18.0"
|
|
65
|
+
},
|
|
60
66
|
"peerDependencies": {
|
|
61
|
-
"@angular/compiler-cli": "^18.0.0-next.0",
|
|
67
|
+
"@angular/compiler-cli": "^18.0.0-next.0 || ^18.1.0-next.0",
|
|
62
68
|
"tailwindcss": "^2.0.0 || ^3.0.0",
|
|
63
69
|
"tslib": "^2.3.0",
|
|
64
70
|
"typescript": ">=5.4 <5.5"
|
package/lib/flatten/esbuild.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { BuildContext, BuildOptions } from 'esbuild';
|
|
2
|
-
import { OutputFileCache } from '../ng-package/nodes';
|
|
3
|
-
/**
|
|
4
|
-
* Options used in `ng-packagr` for writing flat bundle files.
|
|
5
|
-
*
|
|
6
|
-
* These options are passed through to rollup.
|
|
7
|
-
*/
|
|
8
|
-
export interface BundleOptions {
|
|
9
|
-
moduleName: string;
|
|
10
|
-
entry: string;
|
|
11
|
-
outdir: string;
|
|
12
|
-
entryName: string;
|
|
13
|
-
buildContext?: BuildContext;
|
|
14
|
-
fileCache: OutputFileCache;
|
|
15
|
-
watch: boolean;
|
|
16
|
-
}
|
|
17
|
-
export declare function bundle({ entryName, entry, watch, buildContext, outdir }: BundleOptions): Promise<{
|
|
18
|
-
esbuildContext: BuildContext<BuildOptions>;
|
|
19
|
-
outputFiles: import("esbuild").OutputFile[];
|
|
20
|
-
}>;
|
package/lib/flatten/esbuild.js
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.bundle = void 0;
|
|
27
|
-
const esbuild_1 = require("esbuild");
|
|
28
|
-
const path = __importStar(require("path"));
|
|
29
|
-
const log = __importStar(require("../utils/log"));
|
|
30
|
-
async function bundle({ entryName, entry, watch, buildContext, outdir }) {
|
|
31
|
-
var _a, _b;
|
|
32
|
-
const dir = path.dirname(entry);
|
|
33
|
-
const esbuildOptions = {
|
|
34
|
-
// Esbuild will try to locate a tsconfig from the project root.
|
|
35
|
-
// Provide an empty one since we don't want to handle TS code here.
|
|
36
|
-
tsconfigRaw: {},
|
|
37
|
-
format: 'esm',
|
|
38
|
-
outdir,
|
|
39
|
-
bundle: true,
|
|
40
|
-
logLevel: 'silent',
|
|
41
|
-
minify: false,
|
|
42
|
-
legalComments: 'eof',
|
|
43
|
-
packages: 'external',
|
|
44
|
-
write: true,
|
|
45
|
-
entryPoints: [entry],
|
|
46
|
-
resolveExtensions: ['.mjs', '.js'],
|
|
47
|
-
preserveSymlinks: true,
|
|
48
|
-
sourcemap: 'linked',
|
|
49
|
-
absWorkingDir: dir,
|
|
50
|
-
splitting: true,
|
|
51
|
-
treeShaking: false,
|
|
52
|
-
chunkNames: entryName + '-[name]-[hash]',
|
|
53
|
-
entryNames: entryName,
|
|
54
|
-
outExtension: { '.js': '.mjs' },
|
|
55
|
-
charset: 'utf8',
|
|
56
|
-
};
|
|
57
|
-
let esbuildContext;
|
|
58
|
-
if (watch) {
|
|
59
|
-
esbuildContext = buildContext !== null && buildContext !== void 0 ? buildContext : (await (0, esbuild_1.context)(esbuildOptions));
|
|
60
|
-
}
|
|
61
|
-
const { outputFiles, errors, warnings } = await ((_b = (_a = esbuildContext === null || esbuildContext === void 0 ? void 0 : esbuildContext.rebuild) === null || _a === void 0 ? void 0 : _a.call(esbuildContext)) !== null && _b !== void 0 ? _b : (0, esbuild_1.build)(esbuildOptions));
|
|
62
|
-
if (warnings.length > 0) {
|
|
63
|
-
log.warn((await (0, esbuild_1.formatMessages)(warnings, { kind: 'warning' })).join('\n'));
|
|
64
|
-
}
|
|
65
|
-
if (errors.length > 0) {
|
|
66
|
-
log.error((await (0, esbuild_1.formatMessages)(errors, { kind: 'error' })).join('\n'));
|
|
67
|
-
throw new Error(`An error has occuried while processing ${entry}.`);
|
|
68
|
-
}
|
|
69
|
-
return {
|
|
70
|
-
esbuildContext,
|
|
71
|
-
outputFiles: outputFiles,
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
exports.bundle = bundle;
|
|
75
|
-
//# sourceMappingURL=esbuild.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"esbuild.js","sourceRoot":"","sources":["../../../src/lib/flatten/esbuild.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qCAAqF;AACrF,2CAA6B;AAE7B,kDAAoC;AAiB7B,KAAK,UAAU,MAAM,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,EAAiB;;IAC3F,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAChC,MAAM,cAAc,GAAiB;QACnC,+DAA+D;QAC/D,mEAAmE;QACnE,WAAW,EAAE,EAAE;QACf,MAAM,EAAE,KAAK;QACb,MAAM;QACN,MAAM,EAAE,IAAI;QACZ,QAAQ,EAAE,QAAQ;QAClB,MAAM,EAAE,KAAK;QACb,aAAa,EAAE,KAAK;QACpB,QAAQ,EAAE,UAAU;QACpB,KAAK,EAAE,IAAI;QACX,WAAW,EAAE,CAAC,KAAK,CAAC;QACpB,iBAAiB,EAAE,CAAC,MAAM,EAAE,KAAK,CAAC;QAClC,gBAAgB,EAAE,IAAI;QACtB,SAAS,EAAE,QAAQ;QACnB,aAAa,EAAE,GAAG;QAClB,SAAS,EAAE,IAAI;QACf,WAAW,EAAE,KAAK;QAClB,UAAU,EAAE,SAAS,GAAG,gBAAgB;QACxC,UAAU,EAAE,SAAS;QACrB,YAAY,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE;QAC/B,OAAO,EAAE,MAAM;KAChB,CAAC;IAEF,IAAI,cAAwC,CAAC;IAC7C,IAAI,KAAK,EAAE,CAAC;QACV,cAAc,GAAG,YAAY,aAAZ,YAAY,cAAZ,YAAY,GAAI,CAAC,MAAM,IAAA,iBAAO,EAAC,cAAc,CAAC,CAAC,CAAC;IACnE,CAAC;IAED,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,CAAC,MAAA,MAAA,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAE,OAAO,8DAAI,mCAAI,IAAA,eAAK,EAAC,cAAc,CAAC,CAAC,CAAC;IAEvG,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACxB,GAAG,CAAC,IAAI,CAAC,CAAC,MAAM,IAAA,wBAAc,EAAC,QAAQ,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IAC7E,CAAC;IAED,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACtB,GAAG,CAAC,KAAK,CAAC,CAAC,MAAM,IAAA,wBAAc,EAAC,MAAM,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QAExE,MAAM,IAAI,KAAK,CAAC,0CAA0C,KAAK,GAAG,CAAC,CAAC;IACtE,CAAC;IAED,OAAO;QACL,cAAc;QACd,WAAW,EAAE,WAAW;KACzB,CAAC;AACJ,CAAC;AAhDD,wBAgDC","sourcesContent":["import { BuildContext, BuildOptions, build, context, formatMessages } from 'esbuild';\nimport * as path from 'path';\nimport { OutputFileCache } from '../ng-package/nodes';\nimport * as log from '../utils/log';\n\n/**\n * Options used in `ng-packagr` for writing flat bundle files.\n *\n * These options are passed through to rollup.\n */\nexport interface BundleOptions {\n moduleName: string;\n entry: string;\n outdir: string;\n entryName: string;\n buildContext?: BuildContext;\n fileCache: OutputFileCache;\n watch: boolean;\n}\n\nexport async function bundle({ entryName, entry, watch, buildContext, outdir }: BundleOptions) {\n const dir = path.dirname(entry);\n const esbuildOptions: BuildOptions = {\n // Esbuild will try to locate a tsconfig from the project root.\n // Provide an empty one since we don't want to handle TS code here.\n tsconfigRaw: {},\n format: 'esm',\n outdir,\n bundle: true,\n logLevel: 'silent',\n minify: false,\n legalComments: 'eof',\n packages: 'external',\n write: true,\n entryPoints: [entry],\n resolveExtensions: ['.mjs', '.js'],\n preserveSymlinks: true,\n sourcemap: 'linked',\n absWorkingDir: dir,\n splitting: true,\n treeShaking: false,\n chunkNames: entryName + '-[name]-[hash]',\n entryNames: entryName,\n outExtension: { '.js': '.mjs' },\n charset: 'utf8',\n };\n\n let esbuildContext: BuildContext | undefined;\n if (watch) {\n esbuildContext = buildContext ?? (await context(esbuildOptions));\n }\n\n const { outputFiles, errors, warnings } = await (esbuildContext?.rebuild?.() ?? build(esbuildOptions));\n\n if (warnings.length > 0) {\n log.warn((await formatMessages(warnings, { kind: 'warning' })).join('\\n'));\n }\n\n if (errors.length > 0) {\n log.error((await formatMessages(errors, { kind: 'error' })).join('\\n'));\n\n throw new Error(`An error has occuried while processing ${entry}.`);\n }\n\n return {\n esbuildContext,\n outputFiles: outputFiles,\n };\n}\n"]}
|