@servicenow/sdk-repack 2.2.1
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/dist/bundle-artifacts/build-queue.d.ts +8 -0
- package/dist/bundle-artifacts/build-queue.js +42 -0
- package/dist/bundle-artifacts/build-queue.js.map +1 -0
- package/dist/bundle-artifacts/file-system-adapter/rollup-fs-adapter.d.ts +24 -0
- package/dist/bundle-artifacts/file-system-adapter/rollup-fs-adapter.js +94 -0
- package/dist/bundle-artifacts/file-system-adapter/rollup-fs-adapter.js.map +1 -0
- package/dist/bundle-artifacts/index.d.ts +2 -0
- package/dist/bundle-artifacts/index.js +159 -0
- package/dist/bundle-artifacts/index.js.map +1 -0
- package/dist/bundle-artifacts/plugins/config.d.ts +9 -0
- package/dist/bundle-artifacts/plugins/config.js +34 -0
- package/dist/bundle-artifacts/plugins/config.js.map +1 -0
- package/dist/bundle-artifacts/plugins/web-fs-loader.d.ts +12 -0
- package/dist/bundle-artifacts/plugins/web-fs-loader.js +26 -0
- package/dist/bundle-artifacts/plugins/web-fs-loader.js.map +1 -0
- package/dist/bundle-artifacts/support/fs.d.ts +8 -0
- package/dist/bundle-artifacts/support/fs.js +20 -0
- package/dist/bundle-artifacts/support/fs.js.map +1 -0
- package/dist/bundle-artifacts/support/handle-externals.d.ts +3 -0
- package/dist/bundle-artifacts/support/handle-externals.js +24 -0
- package/dist/bundle-artifacts/support/handle-externals.js.map +1 -0
- package/dist/bundle-artifacts/support/package-entry.d.ts +5 -0
- package/dist/bundle-artifacts/support/package-entry.js +68 -0
- package/dist/bundle-artifacts/support/package-entry.js.map +1 -0
- package/dist/bundle-artifacts/support/package-json.d.ts +23 -0
- package/dist/bundle-artifacts/support/package-json.js +135 -0
- package/dist/bundle-artifacts/support/package-json.js.map +1 -0
- package/dist/bundle-artifacts/support/resolver.d.ts +8 -0
- package/dist/bundle-artifacts/support/resolver.js +44 -0
- package/dist/bundle-artifacts/support/resolver.js.map +1 -0
- package/dist/bundle-artifacts/support/types.d.ts +31 -0
- package/dist/bundle-artifacts/support/types.js +3 -0
- package/dist/bundle-artifacts/support/types.js.map +1 -0
- package/dist/bundle-artifacts/types.d.ts +46 -0
- package/dist/bundle-artifacts/types.js +3 -0
- package/dist/bundle-artifacts/types.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -0
- package/license +9 -0
- package/package.json +32 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.JobStack = void 0;
|
|
4
|
+
const package_json_1 = require("./support/package-json");
|
|
5
|
+
class JobStack {
|
|
6
|
+
// Used for keeping track of what dependencies need to be built and which ones have alread been built
|
|
7
|
+
currentJobs = [];
|
|
8
|
+
finishedJobs = [];
|
|
9
|
+
// Callback for adding a dependency to our job list as we see new imports
|
|
10
|
+
pushJob(addedDep) {
|
|
11
|
+
const { dependencyId = '', ...rest } = addedDep;
|
|
12
|
+
// Make sure to allow building new entries for existing dependencies
|
|
13
|
+
const entryList = rest.subPaths?.length ? rest.subPaths : [package_json_1.DEFAULT_EXPORTS_DIR];
|
|
14
|
+
const buildableEntries = entryList
|
|
15
|
+
.map((s) => `${dependencyId}/${s}`)
|
|
16
|
+
// If every entry we want to build is spoken for, the list will be empty
|
|
17
|
+
.filter((be) => !this.finishedJobs.includes(be));
|
|
18
|
+
if (buildableEntries.length > 0) {
|
|
19
|
+
const idx = this.currentJobs.findIndex((e) => e.dependencyId === dependencyId);
|
|
20
|
+
if (idx > -1 && this.currentJobs[idx]) {
|
|
21
|
+
this.currentJobs[idx] = {
|
|
22
|
+
...this.currentJobs[idx],
|
|
23
|
+
subPaths: [...(this.currentJobs[idx]?.subPaths || []), ...(rest.subPaths || [])],
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
this.currentJobs.push(addedDep);
|
|
28
|
+
}
|
|
29
|
+
this.finishedJobs.push(...buildableEntries);
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
hasJobsInQueue() {
|
|
35
|
+
return this.currentJobs.length > 0;
|
|
36
|
+
}
|
|
37
|
+
popJob() {
|
|
38
|
+
return this.currentJobs.pop();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.JobStack = JobStack;
|
|
42
|
+
//# sourceMappingURL=build-queue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-queue.js","sourceRoot":"","sources":["../../src/bundle-artifacts/build-queue.ts"],"names":[],"mappings":";;;AAAA,yDAA4D;AAG5D,MAAa,QAAQ;IACjB,qGAAqG;IAC7F,WAAW,GAAiB,EAAE,CAAA;IAC9B,YAAY,GAAa,EAAE,CAAA;IAEnC,yEAAyE;IAClE,OAAO,CAAC,QAAoB;QAC/B,MAAM,EAAE,YAAY,GAAG,EAAE,EAAE,GAAG,IAAI,EAAE,GAAG,QAAQ,CAAA;QAC/C,oEAAoE;QACpE,MAAM,SAAS,GAAG,IAAI,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,kCAAmB,CAAC,CAAA;QAC/E,MAAM,gBAAgB,GAAG,SAAS;aAC7B,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,YAAY,IAAI,CAAC,EAAE,CAAC;YACnC,wEAAwE;aACvE,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAA;QAEpD,IAAI,gBAAgB,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC9B,MAAM,GAAG,GAAG,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,YAAY,KAAK,YAAY,CAAC,CAAA;YAC9E,IAAI,GAAG,GAAG,CAAC,CAAC,IAAI,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,EAAE,CAAC;gBACpC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG;oBACpB,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC;oBACxB,QAAQ,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,EAAE,QAAQ,IAAI,EAAE,CAAC,EAAE,GAAG,CAAC,IAAI,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC;iBACnF,CAAA;YACL,CAAC;iBAAM,CAAC;gBACJ,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;YACnC,CAAC;YACD,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,gBAAgB,CAAC,CAAA;YAC3C,OAAO,IAAI,CAAA;QACf,CAAC;QACD,OAAO,KAAK,CAAA;IAChB,CAAC;IAEM,cAAc;QACjB,OAAO,IAAI,CAAC,WAAW,CAAC,MAAM,GAAG,CAAC,CAAA;IACtC,CAAC;IAEM,MAAM;QACT,OAAO,IAAI,CAAC,WAAW,CAAC,GAAG,EAAE,CAAA;IACjC,CAAC;CACJ;AAtCD,4BAsCC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { FileSystem } from '@servicenow/sdk-project';
|
|
2
|
+
import type { IsomorphicRollupFs, Stats } from '@servicenow/isomorphic-rollup';
|
|
3
|
+
import type { Dirent, Stats as fstats } from 'fs';
|
|
4
|
+
/**
|
|
5
|
+
* Filesystem wrapper around the filesystem passed in by fluent
|
|
6
|
+
*/
|
|
7
|
+
export declare class RollupFs implements IsomorphicRollupFs {
|
|
8
|
+
private readonly fs;
|
|
9
|
+
promises: any;
|
|
10
|
+
constructor(fs: FileSystem);
|
|
11
|
+
realpath(path: string): Promise<string>;
|
|
12
|
+
realpathSync(path: string): string;
|
|
13
|
+
access(p: string): Promise<boolean>;
|
|
14
|
+
readFile(path: string, encoding?: FileSystem.Encoding): Promise<string>;
|
|
15
|
+
stat(path: string): Promise<Stats>;
|
|
16
|
+
readdir: (path: string, options: {
|
|
17
|
+
withFileTypes: true;
|
|
18
|
+
}, cb: (er: NodeJS.ErrnoException | null, entries?: Dirent[]) => void) => void;
|
|
19
|
+
lstatPromise(path: string): Promise<fstats>;
|
|
20
|
+
readdirPromise(path: string, options: {
|
|
21
|
+
withFileTypes: true;
|
|
22
|
+
}): Promise<Dirent[]>;
|
|
23
|
+
readlinkPromise(path: string): Promise<string>;
|
|
24
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RollupFs = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Filesystem wrapper around the filesystem passed in by fluent
|
|
6
|
+
*/
|
|
7
|
+
class RollupFs {
|
|
8
|
+
fs;
|
|
9
|
+
promises;
|
|
10
|
+
constructor(fs) {
|
|
11
|
+
this.fs = fs;
|
|
12
|
+
// These are used by glob when looking for filesystem APIs. They're very particular about the placement.
|
|
13
|
+
this.promises = {
|
|
14
|
+
lstat: this.lstatPromise,
|
|
15
|
+
readdir: this.readdirPromise,
|
|
16
|
+
readlink: this.readlinkPromise,
|
|
17
|
+
realpath: this.realpath,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
realpath(path) {
|
|
21
|
+
return new Promise((res, rej) => {
|
|
22
|
+
try {
|
|
23
|
+
res(this.fs.realpathSync(path));
|
|
24
|
+
}
|
|
25
|
+
catch (e) {
|
|
26
|
+
rej(e);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
realpathSync(path) {
|
|
31
|
+
return this.fs.realpathSync(path);
|
|
32
|
+
}
|
|
33
|
+
async access(p) {
|
|
34
|
+
try {
|
|
35
|
+
const stat = this.fs.statSync(p);
|
|
36
|
+
return !!stat;
|
|
37
|
+
}
|
|
38
|
+
catch (_) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
readFile(path, encoding) {
|
|
43
|
+
return new Promise((res, rej) => {
|
|
44
|
+
try {
|
|
45
|
+
res(this.fs.readFileSync(path, { encoding: encoding || 'utf-8' }));
|
|
46
|
+
}
|
|
47
|
+
catch (e) {
|
|
48
|
+
rej(e);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
stat(path) {
|
|
53
|
+
return new Promise((res, rej) => {
|
|
54
|
+
try {
|
|
55
|
+
res(this.fs.statSync(path));
|
|
56
|
+
}
|
|
57
|
+
catch (e) {
|
|
58
|
+
rej(e);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
readdir = (path, options, cb) => {
|
|
63
|
+
this.readdirPromise(path, options)
|
|
64
|
+
.then((data) => cb(null, data))
|
|
65
|
+
.catch((err) => cb(err));
|
|
66
|
+
};
|
|
67
|
+
// Promises-based Methods
|
|
68
|
+
lstatPromise(path) {
|
|
69
|
+
return new Promise((res, rej) => {
|
|
70
|
+
try {
|
|
71
|
+
res(this.fs.statSync(path));
|
|
72
|
+
}
|
|
73
|
+
catch (e) {
|
|
74
|
+
rej(e);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
readdirPromise(path, options) {
|
|
79
|
+
return new Promise((res, rej) => {
|
|
80
|
+
try {
|
|
81
|
+
const entries = this.fs.readdirSync(path, options);
|
|
82
|
+
res(entries);
|
|
83
|
+
}
|
|
84
|
+
catch (e) {
|
|
85
|
+
rej(e);
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
async readlinkPromise(path) {
|
|
90
|
+
return this.realpath(path);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
exports.RollupFs = RollupFs;
|
|
94
|
+
//# sourceMappingURL=rollup-fs-adapter.js.map
|
|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CAAC,IAAY,EAAE,OAAgC;QACzD,OAAO,IAAI,OAAO,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;YAC5B,IAAI,CAAC;gBACD,MAAM,OAAO,GAAG,IAAI,CAAC,EAAE,CAAC,WAAW,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;gBAClD,GAAG,CAAC,OAAO,CAAC,CAAA;YAChB,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACT,GAAG,CAAC,CAAC,CAAC,CAAA;YACV,CAAC;QACL,CAAC,CAAC,CAAA;IACN,CAAC;IAED,KAAK,CAAC,eAAe,CAAC,IAAY;QAC9B,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;IAC9B,CAAC;CACJ;AA1FD,4BA0FC"}
|
|
@@ -0,0 +1,159 @@
|
|
|
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.runBuild = void 0;
|
|
7
|
+
const rollup_1 = require("rollup");
|
|
8
|
+
const package_json_1 = require("./support/package-json");
|
|
9
|
+
const handle_externals_1 = __importDefault(require("./support/handle-externals"));
|
|
10
|
+
const config_1 = __importDefault(require("./plugins/config"));
|
|
11
|
+
const sdk_project_1 = require("@servicenow/sdk-project");
|
|
12
|
+
const rollup_fs_adapter_1 = require("./file-system-adapter/rollup-fs-adapter");
|
|
13
|
+
const package_entry_1 = require("./support/package-entry");
|
|
14
|
+
const resolver_1 = require("./support/resolver");
|
|
15
|
+
const build_queue_1 = require("./build-queue");
|
|
16
|
+
const runBuild = async ({ pkgName, entryPoint, outputDir = sdk_project_1.path.join('.now', '.output'), rootDir, fs, options, logger, useWebFsLoader = false, }) => {
|
|
17
|
+
const jobs = new build_queue_1.JobStack();
|
|
18
|
+
// List of completed builds and their outputs
|
|
19
|
+
const nodeList = [];
|
|
20
|
+
const rollUpFS = new rollup_fs_adapter_1.RollupFs(fs);
|
|
21
|
+
// Needs to have `node_modules` in the root path (even if the folder doesn't exist)
|
|
22
|
+
const modulePath = sdk_project_1.path.join(rootDir, 'node_modules');
|
|
23
|
+
const outputPath = sdk_project_1.path.resolve(rootDir, outputDir);
|
|
24
|
+
sdk_project_1.FileSystem.ensureDirSync(fs, outputPath);
|
|
25
|
+
// Our first dependency (the initial dependency request)
|
|
26
|
+
const initialDependency = {
|
|
27
|
+
dependencyId: pkgName,
|
|
28
|
+
subPaths: entryPoint,
|
|
29
|
+
moduleRoot: modulePath,
|
|
30
|
+
};
|
|
31
|
+
// Push our first dependency on the stack
|
|
32
|
+
jobs.pushJob(initialDependency);
|
|
33
|
+
const buildDependency = async ({ subPaths, outDir, options = {
|
|
34
|
+
repackage: { omitProto: true },
|
|
35
|
+
}, dependencyId, importer, requestorModuleRoot, }) => {
|
|
36
|
+
// Get the package json of the dependency we're requesting using the importer as our starting point
|
|
37
|
+
const realPkgJson = await (0, resolver_1.getRealPkgJson)(dependencyId, importer || requestorModuleRoot, rollUpFS);
|
|
38
|
+
// If we didn't find a packag.json, it's possible this dependency is virtual (injected by the build)
|
|
39
|
+
// in which case we just need to resolve relative to our existing root.
|
|
40
|
+
const moduleRoot = realPkgJson ? sdk_project_1.path.dirname(realPkgJson.path) : requestorModuleRoot;
|
|
41
|
+
if (!(0, package_json_1.shouldBundlePkg)(realPkgJson)) {
|
|
42
|
+
logger.info(`Not bundling ${dependencyId}`);
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
(0, package_json_1.notifyUserOfFluentDependency)(realPkgJson, moduleRoot, logger, fs);
|
|
46
|
+
// If we didn't find a package json, just default the version to 1.0.0
|
|
47
|
+
const version = realPkgJson?.packageJson['version'] || package_json_1.FALLBACK_VERSION;
|
|
48
|
+
logger.info(`Building ${dependencyId} ${version}...`);
|
|
49
|
+
// Our output setup
|
|
50
|
+
// https://rollupjs.org/configuration-options
|
|
51
|
+
const outputConfig = {
|
|
52
|
+
format: 'cjs', // output to common-js
|
|
53
|
+
interop: 'compat', // handle module interop when handling default imports
|
|
54
|
+
intro: 'var __global$ = globalThis || (typeof window !== "undefined" ? window : self);',
|
|
55
|
+
};
|
|
56
|
+
try {
|
|
57
|
+
const { input: inputMap, output: outputMap } = await (0, package_entry_1.getInputMap)(realPkgJson, subPaths, dependencyId);
|
|
58
|
+
const importedPackages = new Set();
|
|
59
|
+
const captureImportedPackages = ({ moduleName }) => {
|
|
60
|
+
importedPackages.add(moduleName);
|
|
61
|
+
};
|
|
62
|
+
const bundle = await (0, rollup_1.rollup)({
|
|
63
|
+
input: inputMap,
|
|
64
|
+
output: outputConfig,
|
|
65
|
+
// Needed for pnpm to resolve properly (should do nothing in browser environments -> all symlink resolution just returns the same path)
|
|
66
|
+
preserveSymlinks: true,
|
|
67
|
+
// This will handle import/requires from the build, add external dependencies as new build requests,
|
|
68
|
+
// and set the request as an external
|
|
69
|
+
external: (0, handle_externals_1.default)({
|
|
70
|
+
cb: captureImportedPackages,
|
|
71
|
+
addDependency: jobs.pushJob.bind(jobs),
|
|
72
|
+
dependencyId,
|
|
73
|
+
moduleRoot,
|
|
74
|
+
}),
|
|
75
|
+
plugins: (0, config_1.default)({ moduleRoot, rollUpFS, useWebFsLoader }),
|
|
76
|
+
});
|
|
77
|
+
const { output: buildOutput } = await bundle.generate(outputConfig);
|
|
78
|
+
const depOutputDir = sdk_project_1.path.join(rootDir, outDir, dependencyId, version);
|
|
79
|
+
sdk_project_1.FileSystem.ensureDirSync(fs, depOutputDir);
|
|
80
|
+
const fileList = [];
|
|
81
|
+
for (const file of buildOutput) {
|
|
82
|
+
if (file.type === 'chunk') {
|
|
83
|
+
let code = file.code;
|
|
84
|
+
/**
|
|
85
|
+
* rollup uses __proto__ as a performant way of removing prototypes from objects
|
|
86
|
+
* we've configured rhino to throw errors when __proto__ is used. we might want to fix this.
|
|
87
|
+
*
|
|
88
|
+
* Evaluator: org.mozilla.javascript.EcmaError: .__proto__ not allowed
|
|
89
|
+
* Caused by error in script at line 1
|
|
90
|
+
*
|
|
91
|
+
* For now, we just drop __proto__.
|
|
92
|
+
*/
|
|
93
|
+
if (options.repackage.omitProto) {
|
|
94
|
+
code = code.replaceAll(/__proto__: ?null,?/g, '');
|
|
95
|
+
}
|
|
96
|
+
// resolve the output path
|
|
97
|
+
const jsOutputPath = sdk_project_1.path.resolve(sdk_project_1.path.join(depOutputDir, file.fileName));
|
|
98
|
+
const fileDir = sdk_project_1.path.dirname(jsOutputPath);
|
|
99
|
+
sdk_project_1.FileSystem.ensureDirSync(fs, fileDir);
|
|
100
|
+
// write our file
|
|
101
|
+
fs.writeFileSync(jsOutputPath, code, { encoding: 'utf-8' });
|
|
102
|
+
// keep track of our imports and outputted files
|
|
103
|
+
fileList.push(file.fileName);
|
|
104
|
+
}
|
|
105
|
+
else if (file.type === 'asset') {
|
|
106
|
+
// this will likely be package.json or sbom files
|
|
107
|
+
const assetOutputPath = sdk_project_1.path.resolve(sdk_project_1.path.join(depOutputDir, file.fileName));
|
|
108
|
+
const fileDir = sdk_project_1.path.dirname(assetOutputPath);
|
|
109
|
+
sdk_project_1.FileSystem.ensureDirSync(fs, fileDir);
|
|
110
|
+
fs.writeFileSync(assetOutputPath, file.source, { encoding: 'utf-8' });
|
|
111
|
+
fileList.push(file.fileName);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
const outFiles = fileList.map((fileName) => {
|
|
115
|
+
if (fileName in outputMap) {
|
|
116
|
+
return { name: fileName, path: outputMap[fileName] };
|
|
117
|
+
}
|
|
118
|
+
return { name: fileName };
|
|
119
|
+
});
|
|
120
|
+
// generate a package.json that'll play nicely in rhino
|
|
121
|
+
const { packageJson } = await (0, package_json_1.writePackageJson)(dependencyId, outFiles, [...importedPackages], depOutputDir, realPkgJson, rollUpFS, fs);
|
|
122
|
+
// create our output manifest
|
|
123
|
+
const outputs = {
|
|
124
|
+
files: [...fileList, 'package.json'],
|
|
125
|
+
packagePath: depOutputDir,
|
|
126
|
+
updatedManifest: packageJson,
|
|
127
|
+
};
|
|
128
|
+
return outputs;
|
|
129
|
+
}
|
|
130
|
+
catch (error) {
|
|
131
|
+
logger.info(error.toString());
|
|
132
|
+
}
|
|
133
|
+
return undefined;
|
|
134
|
+
};
|
|
135
|
+
// Iterate over our list of dependencies until the list is empty (no more build requests)
|
|
136
|
+
while (jobs.hasJobsInQueue()) {
|
|
137
|
+
const nextup = jobs.popJob();
|
|
138
|
+
if (!nextup) {
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
const { dependencyId, subPaths, moduleRoot, importer } = nextup;
|
|
142
|
+
const depNode = await buildDependency({
|
|
143
|
+
subPaths: subPaths?.filter((o) => o),
|
|
144
|
+
outDir: outputDir,
|
|
145
|
+
options,
|
|
146
|
+
dependencyId,
|
|
147
|
+
importer,
|
|
148
|
+
// The old module root will be the requestor of this new dependency
|
|
149
|
+
requestorModuleRoot: moduleRoot,
|
|
150
|
+
});
|
|
151
|
+
if (!depNode) {
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
nodeList.push(depNode);
|
|
155
|
+
}
|
|
156
|
+
return nodeList;
|
|
157
|
+
};
|
|
158
|
+
exports.runBuild = runBuild;
|
|
159
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/bundle-artifacts/index.ts"],"names":[],"mappings":";;;;;;AAAA,mCAA8C;AAC9C,yDAK+B;AAC/B,kFAAwD;AACxD,8DAA2C;AAC3C,yDAA0D;AAC1D,+EAAkE;AAElE,2DAAqD;AACrD,iDAAmD;AACnD,+CAAwC;AAEjC,MAAM,QAAQ,GAAG,KAAK,EAAE,EAC3B,OAAO,EACP,UAAU,EACV,SAAS,GAAG,kBAAI,CAAC,IAAI,CAAC,MAAM,EAAE,SAAS,CAAC,EACxC,OAAO,EACP,EAAE,E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;QAED,OAAO,SAAS,CAAA;IACpB,CAAC,CAAA;IAED,yFAAyF;IACzF,OAAO,IAAI,CAAC,cAAc,EAAE,EAAE,CAAC;QAC3B,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,EAAE,CAAA;QAC5B,IAAI,CAAC,MAAM,EAAE,CAAC;YACV,SAAQ;QACZ,CAAC;QACD,MAAM,EAAE,YAAY,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAE,GAAG,MAAM,CAAA;QAC/D,MAAM,OAAO,GAAG,MAAM,eAAe,CAAC;YAClC,QAAQ,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;YACpC,MAAM,EAAE,SAAS;YACjB,OAAO;YACP,YAAY;YACZ,QAAQ;YACR,mEAAmE;YACnE,mBAAmB,EAAE,UAAU;SAClC,CAAC,CAAA;QAEF,IAAI,CAAC,OAAO,EAAE,CAAC;YACX,SAAQ;QACZ,CAAC;QACD,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IAC1B,CAAC;IACD,OAAO,QAAQ,CAAA;AACnB,CAAC,CAAA;AAnLY,QAAA,QAAQ,YAmLpB"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { IsomorphicRollupFs } from '@servicenow/isomorphic-rollup';
|
|
2
|
+
import type { Plugin } from 'rollup';
|
|
3
|
+
export type PluginOptions = {
|
|
4
|
+
moduleRoot: string;
|
|
5
|
+
rollUpFS: IsomorphicRollupFs;
|
|
6
|
+
useWebFsLoader: boolean;
|
|
7
|
+
};
|
|
8
|
+
declare const _default: ({ moduleRoot, rollUpFS, useWebFsLoader }: PluginOptions) => Plugin[];
|
|
9
|
+
export default _default;
|
|
@@ -0,0 +1,34 @@
|
|
|
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
|
+
const isomorphic_rollup_1 = require("@servicenow/isomorphic-rollup");
|
|
7
|
+
const web_fs_loader_1 = __importDefault(require("./web-fs-loader"));
|
|
8
|
+
const compact = (list) => list.filter((o) => o);
|
|
9
|
+
// https://github.com/flexdinesh/browser-or-node/blob/master/src/index.ts#L12C1-L15C58
|
|
10
|
+
const isWebWorker = typeof self === 'object' && self.constructor && self.constructor.name === 'DedicatedWorkerGlobalScope';
|
|
11
|
+
exports.default = ({ moduleRoot, rollUpFS, useWebFsLoader }) => compact([
|
|
12
|
+
(0, isomorphic_rollup_1.replace)({
|
|
13
|
+
'global*': '__global$*',
|
|
14
|
+
preventAssignment: true,
|
|
15
|
+
'process.env.NODE_ENV': 'production',
|
|
16
|
+
}),
|
|
17
|
+
(0, isomorphic_rollup_1.json)(),
|
|
18
|
+
(0, isomorphic_rollup_1.nodeResolve)({ fs: rollUpFS, rootDir: moduleRoot, preferBuiltins: false }),
|
|
19
|
+
(0, isomorphic_rollup_1.swc)({
|
|
20
|
+
swc: {
|
|
21
|
+
jsc: {
|
|
22
|
+
parser: {
|
|
23
|
+
jsx: true,
|
|
24
|
+
syntax: 'ecmascript',
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
}),
|
|
29
|
+
(0, isomorphic_rollup_1.commonjs)({ fs: rollUpFS, rootDir: moduleRoot, dynamicRequireRoot: moduleRoot }),
|
|
30
|
+
(0, isomorphic_rollup_1.polyfill)(),
|
|
31
|
+
(isWebWorker || useWebFsLoader) && (0, web_fs_loader_1.default)({ fs: rollUpFS }),
|
|
32
|
+
(0, isomorphic_rollup_1.rollupPluginSbom)({ fs: rollUpFS, outFormats: ['json'], includeWellKnown: false }),
|
|
33
|
+
]);
|
|
34
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/bundle-artifacts/plugins/config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@
|
|
|
1
|
+
import { InputPluginOption } from 'rollup';
|
|
2
|
+
import { IsomorphicRollupFs } from '@servicenow/isomorphic-rollup';
|
|
3
|
+
export type WebFSLoaderOptions = {
|
|
4
|
+
fs: IsomorphicRollupFs;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* This plugin is the backstop for file resolution & loading when no other plugin has loaded a file for rollup.
|
|
8
|
+
* On the node environment, rollup will handle the final path resolution and file loading, but in the browser
|
|
9
|
+
* you must provide your own implementation for this.
|
|
10
|
+
*/
|
|
11
|
+
declare const _default: (opt: WebFSLoaderOptions) => InputPluginOption;
|
|
12
|
+
export default _default;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const fs_1 = require("../support/fs");
|
|
4
|
+
/**
|
|
5
|
+
* This plugin is the backstop for file resolution & loading when no other plugin has loaded a file for rollup.
|
|
6
|
+
* On the node environment, rollup will handle the final path resolution and file loading, but in the browser
|
|
7
|
+
* you must provide your own implementation for this.
|
|
8
|
+
*/
|
|
9
|
+
exports.default = (opt) => {
|
|
10
|
+
return {
|
|
11
|
+
name: 'rollup-web-fs',
|
|
12
|
+
resolveId: {
|
|
13
|
+
order: 'post',
|
|
14
|
+
async handler(importee, importer) {
|
|
15
|
+
if (await (0, fs_1.fileExists)(importee, opt.fs)) {
|
|
16
|
+
return importee;
|
|
17
|
+
}
|
|
18
|
+
throw new Error(`Could not resolve import "${importee}" from "${importer}"`);
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
load(id) {
|
|
22
|
+
return opt.fs.readFile(id);
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=web-fs-loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web-fs-loader.js","sourceRoot":"","sources":["../../../src/bundle-artifacts/plugins/web-fs-loader.ts"],"names":[],"mappings":";;AAEA,sCAA0C;AAM1C;;;;GAIG;AACH,kBAAe,CAAC,GAAuB,EAAqB,EAAE;IAC1D,OAAO;QACH,IAAI,EAAE,eAAe;QACrB,SAAS,EAAE;YACP,KAAK,EAAE,MAAM;YACb,KAAK,CAAC,OAAO,CAAC,QAAQ,EAAE,QAAQ;gBAC5B,IAAI,MAAM,IAAA,eAAU,EAAC,QAAQ,EAAE,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC;oBACrC,OAAO,QAAQ,CAAA;gBACnB,CAAC;gBACD,MAAM,IAAI,KAAK,CAAC,6BAA6B,QAAQ,WAAW,QAAQ,GAAG,CAAC,CAAA;YAChF,CAAC;SACJ;QACD,IAAI,CAAC,EAAE;YACH,OAAO,GAAG,CAAC,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAA;QAC9B,CAAC;KACJ,CAAA;AACL,CAAC,CAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { IsomorphicRollupFs } from '@servicenow/isomorphic-rollup';
|
|
2
|
+
/**
|
|
3
|
+
* Check if a path exists and if the path belongs to a file
|
|
4
|
+
* @param filePath - Path to check
|
|
5
|
+
* @param fs - Filesystem wrapper for rollup
|
|
6
|
+
* @returns true - path exists and it's a file, false - path doesn't exist or isn't a file
|
|
7
|
+
*/
|
|
8
|
+
export declare const fileExists: (filePath: string, fs: IsomorphicRollupFs) => Promise<boolean>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fileExists = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Check if a path exists and if the path belongs to a file
|
|
6
|
+
* @param filePath - Path to check
|
|
7
|
+
* @param fs - Filesystem wrapper for rollup
|
|
8
|
+
* @returns true - path exists and it's a file, false - path doesn't exist or isn't a file
|
|
9
|
+
*/
|
|
10
|
+
const fileExists = async (filePath, fs) => {
|
|
11
|
+
try {
|
|
12
|
+
const res = await fs.stat(filePath);
|
|
13
|
+
return res.isFile();
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
exports.fileExists = fileExists;
|
|
20
|
+
//# sourceMappingURL=fs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fs.js","sourceRoot":"","sources":["../../../src/bundle-artifacts/support/fs.ts"],"names":[],"mappings":";;;AAEA;;;;;GAKG;AACI,MAAM,UAAU,GAAG,KAAK,EAAE,QAAgB,EAAE,EAAsB,EAAE,EAAE;IACzE,IAAI,CAAC;QACD,MAAM,GAAG,GAAG,MAAM,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;QACnC,OAAO,GAAG,CAAC,MAAM,EAAE,CAAA;IACvB,CAAC;IAAC,MAAM,CAAC;QACL,OAAO,KAAK,CAAA;IAChB,CAAC;AACL,CAAC,CAAA;AAPY,QAAA,UAAU,cAOtB"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const resolver_1 = require("./resolver");
|
|
4
|
+
exports.default = (options) => {
|
|
5
|
+
const { addDependency, dependencyId } = options;
|
|
6
|
+
const handler = (id, parentId, isResolved) => {
|
|
7
|
+
const { moduleName, entry } = (0, resolver_1.splitModuleRequest)(id);
|
|
8
|
+
if (moduleName && moduleName !== dependencyId && !isResolved) {
|
|
9
|
+
if (options?.cb) {
|
|
10
|
+
options.cb({ moduleName });
|
|
11
|
+
}
|
|
12
|
+
addDependency({
|
|
13
|
+
dependencyId: moduleName,
|
|
14
|
+
moduleRoot: options.moduleRoot,
|
|
15
|
+
importer: parentId,
|
|
16
|
+
subPaths: [entry || '.'],
|
|
17
|
+
});
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
return false;
|
|
21
|
+
};
|
|
22
|
+
return handler;
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=handle-externals.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handle-externals.js","sourceRoot":"","sources":["../../../src/bundle-artifacts/support/handle-externals.ts"],"names":[],"mappings":";;AAAA,yCAA+C;AAG/C,kBAAe,CAAC,OAA0B,EAAmB,EAAE;IAC3D,MAAM,EAAE,aAAa,EAAE,YAAY,EAAE,GAAG,OAAO,CAAA;IAC/C,MAAM,OAAO,GAAG,CAAC,EAAU,EAAE,QAA4B,EAAE,UAAmB,EAAE,EAAE;QAC9E,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,GAAG,IAAA,6BAAkB,EAAC,EAAE,CAAC,CAAA;QACpD,IAAI,UAAU,IAAI,UAAU,KAAK,YAAY,IAAI,CAAC,UAAU,EAAE,CAAC;YAC3D,IAAI,OAAO,EAAE,EAAE,EAAE,CAAC;gBACd,OAAO,CAAC,EAAE,CAAC,EAAE,UAAU,EAAE,CAAC,CAAA;YAC9B,CAAC;YACD,aAAa,CAAC;gBACV,YAAY,EAAE,UAAU;gBACxB,UAAU,EAAE,OAAO,CAAC,UAAU;gBAC9B,QAAQ,EAAE,QAAQ;gBAClB,QAAQ,EAAE,CAAC,KAAK,IAAI,GAAG,CAAC;aAC3B,CAAC,CAAA;YACF,OAAO,IAAI,CAAA;QACf,CAAC;QAED,OAAO,KAAK,CAAA;IAChB,CAAC,CAAA;IAED,OAAO,OAAO,CAAA;AAClB,CAAC,CAAA"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getInputMap = getInputMap;
|
|
4
|
+
const sdk_project_1 = require("@servicenow/sdk-project");
|
|
5
|
+
const package_json_1 = require("./package-json");
|
|
6
|
+
async function getInputMap(packageJson, subPaths, dependencyName = '') {
|
|
7
|
+
if (!packageJson) {
|
|
8
|
+
return getSubPathInputMap(subPaths, dependencyName);
|
|
9
|
+
}
|
|
10
|
+
const exports = packageJson.packageJson.exports;
|
|
11
|
+
if (exports) {
|
|
12
|
+
return getExportsInputMap(exports, dependencyName);
|
|
13
|
+
}
|
|
14
|
+
if (subPaths && subPaths.length > 0) {
|
|
15
|
+
return getSubPathInputMap(subPaths, dependencyName);
|
|
16
|
+
}
|
|
17
|
+
return { input: {}, output: {} };
|
|
18
|
+
}
|
|
19
|
+
function getSubPathInputMap(subPaths, dependencyName) {
|
|
20
|
+
const result = { input: {}, output: {} };
|
|
21
|
+
if (!subPaths) {
|
|
22
|
+
return result;
|
|
23
|
+
}
|
|
24
|
+
return subPaths?.reduce((map, sp) => {
|
|
25
|
+
let entryName = sp.substring(0, sp.length - sdk_project_1.path.extname(sp).length);
|
|
26
|
+
if (entryName === package_json_1.DEFAULT_EXPORTS_DIR) {
|
|
27
|
+
entryName = 'index';
|
|
28
|
+
}
|
|
29
|
+
const outputName = `${entryName}.js`;
|
|
30
|
+
const entryTarget = sp === package_json_1.DEFAULT_EXPORTS_DIR ? dependencyName : sdk_project_1.path.join(dependencyName, sp);
|
|
31
|
+
return {
|
|
32
|
+
input: { ...map.input, [entryName]: entryTarget },
|
|
33
|
+
output: { ...map.output, [outputName]: outputName },
|
|
34
|
+
};
|
|
35
|
+
}, result);
|
|
36
|
+
}
|
|
37
|
+
function getExportsInputMap(exports, dependencyName) {
|
|
38
|
+
const input = {};
|
|
39
|
+
const output = {};
|
|
40
|
+
/**
|
|
41
|
+
* FIXME: We're definitely not handling this properly. We need to improve how we map exports to entries.
|
|
42
|
+
* This is supposed to describe the condition of the import. We're disregarding the conditional scoping
|
|
43
|
+
* and circumventing the existing exports resolution logic in the rollup resolver plugin. We should only concern
|
|
44
|
+
* ourselves with building the asked for entry points and the main entry.
|
|
45
|
+
* https://nodejs.org/api/packages.html#nested-conditions
|
|
46
|
+
* https://github.com/rollup/plugins/tree/master/packages/node-resolve#exportconditions
|
|
47
|
+
*/
|
|
48
|
+
if (exports.import) {
|
|
49
|
+
input['index'] = sdk_project_1.path.join(dependencyName);
|
|
50
|
+
output['index.js'] = 'index.js';
|
|
51
|
+
return {
|
|
52
|
+
input,
|
|
53
|
+
output,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
Object.keys(exports).forEach((exp) => {
|
|
57
|
+
const inputName = exp === package_json_1.DEFAULT_EXPORTS_DIR ? 'index' : exp.substring(0, exp.length - sdk_project_1.path.extname(exp).length);
|
|
58
|
+
const outputName = `${inputName}.js`;
|
|
59
|
+
const inputFile = exp === package_json_1.DEFAULT_EXPORTS_DIR ? '' : exp;
|
|
60
|
+
input[sdk_project_1.path.join(inputName)] = sdk_project_1.path.join(dependencyName, inputFile);
|
|
61
|
+
output[sdk_project_1.path.join(outputName)] = outputName;
|
|
62
|
+
});
|
|
63
|
+
return {
|
|
64
|
+
input,
|
|
65
|
+
output,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=package-entry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package-entry.js","sourceRoot":"","sources":["../../../src/bundle-artifacts/support/package-entry.ts"],"names":[],"mappings":";;AAIA,kCAmBC;AAvBD,yDAA8C;AAC9C,iDAAoD;AAG7C,KAAK,UAAU,WAAW,CAC7B,WAAoC,EACpC,QAA8B,EAC9B,iBAAyB,EAAE;IAE3B,IAAI,CAAC,WAAW,EAAE,CAAC;QACf,OAAO,kBAAkB,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAA;IACvD,CAAC;IAED,MAAM,OAAO,GAAG,WAAW,CAAC,WAAW,CAAC,OAAO,CAAA;IAE/C,IAAI,OAAO,EAAE,CAAC;QACV,OAAO,kBAAkB,CAAC,OAAO,EAAE,cAAc,CAAC,CAAA;IACtD,CAAC;IACD,IAAI,QAAQ,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAClC,OAAO,kBAAkB,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAA;IACvD,CAAC;IAED,OAAO,EA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AG,kBAAI,CAAC,IAAI,CAAC,cAAc,CAAC,CAAA;QAC1C,MAAM,CAAC,UAAU,CAAC,GAAG,UAAU,CAAA;QAC/B,OAAO;YACH,KAAK;YACL,MAAM;SACT,CAAA;IACL,CAAC;IAED,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;QACjC,MAAM,SAAS,GACX,GAAG,KAAK,kCAAmB,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,MAAM,GAAG,kBAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAA;QAEnG,MAAM,UAAU,GAAG,GAAG,SAAS,KAAK,CAAA;QACpC,MAAM,SAAS,GAAG,GAAG,KAAK,kCAAmB,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAA;QAExD,KAAK,CAAC,kBAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,GAAG,kBAAI,CAAC,IAAI,CAAC,cAAc,EAAE,SAAS,CAAC,CAAA;QAClE,MAAM,CAAC,kBAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,GAAG,UAAU,CAAA;IAC9C,CAAC,CAAC,CAAA;IAEF,OAAO;QACH,KAAK;QACL,MAAM;KACT,CAAA;AACL,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { FileSystem, Logger } from '@servicenow/sdk-project';
|
|
2
|
+
import { RollupFs } from '../file-system-adapter/rollup-fs-adapter';
|
|
3
|
+
import { OutFile, RealPkgJson } from './types';
|
|
4
|
+
export declare const DEFAULT_EXPORTS_DIR = ".";
|
|
5
|
+
export declare const FALLBACK_VERSION = "1.0.0";
|
|
6
|
+
export declare function notifyUserOfFluentDependency(realPkgJson: RealPkgJson | undefined, moduleRoot: string, logger: Logger, fs: FileSystem): void;
|
|
7
|
+
export declare function shouldBundlePkg(realPkgJson: RealPkgJson | undefined): boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Creates a simplified package.json with a pinned dependency section and a list of exports matching the
|
|
10
|
+
* built files.
|
|
11
|
+
* @param dependencyName - Name of the dependency
|
|
12
|
+
* @param outFiles - Files we built from the dependency
|
|
13
|
+
* @param imports - List of imports we picked up while building the dependency
|
|
14
|
+
* @param outDir - Output path
|
|
15
|
+
* @param realPkgJson - The real package.json from the dependency
|
|
16
|
+
* @param rollupFs - Filesystem wrapper for rollup
|
|
17
|
+
* @param fs - Filesystem wrapper from fluent
|
|
18
|
+
* @returns modified package.json and output path
|
|
19
|
+
*/
|
|
20
|
+
export declare const writePackageJson: (dependencyName: string | undefined, outFiles: OutFile[], imports: string[], outDir: string, realPkgJson: RealPkgJson | undefined, rollupFs: RollupFs, fs: FileSystem) => Promise<{
|
|
21
|
+
packageJsonPath: string;
|
|
22
|
+
packageJson: any;
|
|
23
|
+
}>;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.writePackageJson = exports.FALLBACK_VERSION = exports.DEFAULT_EXPORTS_DIR = void 0;
|
|
4
|
+
exports.notifyUserOfFluentDependency = notifyUserOfFluentDependency;
|
|
5
|
+
exports.shouldBundlePkg = shouldBundlePkg;
|
|
6
|
+
const sdk_project_1 = require("@servicenow/sdk-project");
|
|
7
|
+
const fs_1 = require("./fs");
|
|
8
|
+
const resolver_1 = require("./resolver");
|
|
9
|
+
exports.DEFAULT_EXPORTS_DIR = '.';
|
|
10
|
+
exports.FALLBACK_VERSION = '1.0.0';
|
|
11
|
+
const DO_NOT_BUILD_THESE_PACKAGES = ['@servicenow/glide'];
|
|
12
|
+
const createFallbackPkgJson = (name = '', imports, outFiles) => {
|
|
13
|
+
const packageJson = {
|
|
14
|
+
name,
|
|
15
|
+
version: exports.FALLBACK_VERSION,
|
|
16
|
+
exports: getExportsField(outFiles),
|
|
17
|
+
dependencies: {},
|
|
18
|
+
};
|
|
19
|
+
imports.forEach((i) => {
|
|
20
|
+
packageJson.dependencies[i] = exports.FALLBACK_VERSION;
|
|
21
|
+
});
|
|
22
|
+
return packageJson;
|
|
23
|
+
};
|
|
24
|
+
function notifyUserOfFluentDependency(realPkgJson, moduleRoot, logger, fs) {
|
|
25
|
+
if (realPkgJson && (0, sdk_project_1.hasNowConfig)(moduleRoot, fs)) {
|
|
26
|
+
const packageJson = realPkgJson.packageJson;
|
|
27
|
+
const { name } = packageJson;
|
|
28
|
+
logger.info(`${name} is a ServiceNow Scoped App and will not be installed automatically.`);
|
|
29
|
+
logger.info(`You will be able to use JavaScript Modules from ${name} but please make sure it is installed on your ServiceNow instance to use any other application resources.`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function shouldBundlePkg(realPkgJson) {
|
|
33
|
+
// If the there's no package.json for the path (it's a singular file, possibly doesn't exist), bundle it
|
|
34
|
+
if (!realPkgJson) {
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
const packageJson = realPkgJson.packageJson;
|
|
38
|
+
const { name } = packageJson;
|
|
39
|
+
// If the package is NOT in this list of packages we purposely exclude, bundle it.
|
|
40
|
+
return !DO_NOT_BUILD_THESE_PACKAGES.includes(name);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Creates a simplified package.json with a pinned dependency section and a list of exports matching the
|
|
44
|
+
* built files.
|
|
45
|
+
* @param dependencyName - Name of the dependency
|
|
46
|
+
* @param outFiles - Files we built from the dependency
|
|
47
|
+
* @param imports - List of imports we picked up while building the dependency
|
|
48
|
+
* @param outDir - Output path
|
|
49
|
+
* @param realPkgJson - The real package.json from the dependency
|
|
50
|
+
* @param rollupFs - Filesystem wrapper for rollup
|
|
51
|
+
* @param fs - Filesystem wrapper from fluent
|
|
52
|
+
* @returns modified package.json and output path
|
|
53
|
+
*/
|
|
54
|
+
const writePackageJson = async (dependencyName = '', outFiles, imports, outDir, realPkgJson, rollupFs, fs) => {
|
|
55
|
+
let packageJson;
|
|
56
|
+
const packageJsonPath = sdk_project_1.path.resolve(sdk_project_1.path.join(outDir, 'package.json'));
|
|
57
|
+
// If the package.json already exists (we built this module before, lets just update the exports)
|
|
58
|
+
if (realPkgJson && (await (0, fs_1.fileExists)(packageJsonPath, rollupFs))) {
|
|
59
|
+
packageJson = JSON.parse(await rollupFs.readFile(packageJsonPath, 'utf-8'));
|
|
60
|
+
packageJson['exports'] = { ...packageJson['exports'], ...getExportsField(outFiles) };
|
|
61
|
+
packageJson['dependencies'] = {
|
|
62
|
+
...packageJson['dependencies'],
|
|
63
|
+
...(await getDependencies(sdk_project_1.path.dirname(realPkgJson.path), imports, outFiles, rollupFs)),
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
else if (realPkgJson) {
|
|
67
|
+
packageJson = realPkgJson.packageJson;
|
|
68
|
+
delete packageJson['module'];
|
|
69
|
+
delete packageJson['browser'];
|
|
70
|
+
delete packageJson['exports'];
|
|
71
|
+
delete packageJson['main'];
|
|
72
|
+
packageJson['exports'] = getExportsField(outFiles);
|
|
73
|
+
packageJson['dependencies'] = await getDependencies(sdk_project_1.path.dirname(realPkgJson.path), imports, outFiles, rollupFs);
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
packageJson = createFallbackPkgJson(dependencyName, imports, outFiles);
|
|
77
|
+
}
|
|
78
|
+
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2), { encoding: 'utf-8' });
|
|
79
|
+
return { packageJsonPath, packageJson };
|
|
80
|
+
};
|
|
81
|
+
exports.writePackageJson = writePackageJson;
|
|
82
|
+
/**
|
|
83
|
+
* Generates an export mapping using the files from a dependency build
|
|
84
|
+
* @param outFiles - List of files built (for additional export paths)
|
|
85
|
+
* @returns export map
|
|
86
|
+
*/
|
|
87
|
+
function getExportsField(outFiles) {
|
|
88
|
+
const out = outFiles.reduce((acc, { name: fileName, path }) => {
|
|
89
|
+
if (!path) {
|
|
90
|
+
return acc;
|
|
91
|
+
}
|
|
92
|
+
else if (fileName === 'index.js') {
|
|
93
|
+
acc[exports.DEFAULT_EXPORTS_DIR] = `./${fileName}`;
|
|
94
|
+
}
|
|
95
|
+
else if (!path.startsWith(exports.DEFAULT_EXPORTS_DIR)) {
|
|
96
|
+
acc[`./${path}`] = `./${fileName}`;
|
|
97
|
+
}
|
|
98
|
+
else if (path) {
|
|
99
|
+
acc[path] = `./${fileName}`;
|
|
100
|
+
}
|
|
101
|
+
return acc;
|
|
102
|
+
}, {});
|
|
103
|
+
return out;
|
|
104
|
+
}
|
|
105
|
+
async function getDependencies(packageRoot, imports, outFiles, rollUpFS) {
|
|
106
|
+
const importModules = imports.reduce((acc, i) => {
|
|
107
|
+
const { moduleName } = (0, resolver_1.splitModuleRequest)(i);
|
|
108
|
+
if (moduleName && !(moduleName in acc)) {
|
|
109
|
+
acc[moduleName] = i;
|
|
110
|
+
}
|
|
111
|
+
return acc;
|
|
112
|
+
}, {});
|
|
113
|
+
const uniqueImports = new Set(Object.keys(importModules));
|
|
114
|
+
const dependencies = {};
|
|
115
|
+
for (const i of uniqueImports) {
|
|
116
|
+
if (outFiles.some(({ name }) => name === i)) {
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
dependencies[i] = await getDependencyVersion(i, packageRoot, rollUpFS);
|
|
120
|
+
}
|
|
121
|
+
return dependencies;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Find a package.json and get the version
|
|
125
|
+
* @param dependencyName - The name of the dependency
|
|
126
|
+
* @param packageRoot - The path to start our search from
|
|
127
|
+
* @param rollUpFS - Filesystem wrapper for rollup
|
|
128
|
+
* @returns The dependency version or 1.0.0 (if the dependency doesn't exist)
|
|
129
|
+
*/
|
|
130
|
+
async function getDependencyVersion(dependencyName, packageRoot, rollUpFS) {
|
|
131
|
+
// Any subpath will yield a decent search, it just can't be the exact package root
|
|
132
|
+
const pkgJson = await (0, resolver_1.getRealPkgJson)(dependencyName, sdk_project_1.path.join(packageRoot, 'package.json'), rollUpFS);
|
|
133
|
+
return pkgJson?.packageJson?.version || exports.FALLBACK_VERSION;
|
|
134
|
+
}
|
|
135
|
+
//# sourceMappingURL=package-json.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package-json.js","sourceRoot":"","sources":["../../../src/bundle-artifacts/support/package-json.ts"],"names":[],"mappings":";;;AAuBA,oEAcC;AAED,0CAUC;AAjDD,yDAAgF;AAEhF,6BAAiC;AAEjC,yCAA+D;AAElD,QAAA,mBAAmB,GAAG,GAAG,CAAA;AACzB,QAAA,gBAAgB,GAAG,OAAO,CAAA;AACvC,MAAM,2BAA2B,GAAG,CAAC,mBAAmB,CAAC,CAAA;AAEzD,MAAM,qBAAqB,GAAG,CAAC,OAAe,EAAE,EAAE,OAAiB,EAAE,QAAmB,EAAE,EAAE;IACxF,MAAM,WAAW,GAAgB;QAC7B,IAAI;QACJ,OAAO,EAAE,wBAAgB;QACzB,OAAO,EAAE,eAAe,CAAC,QAAQ,CAAC;QAClC,YAAY,EAAE,EAAE;KACnB,CAAA;IACD,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE;QAClB,WAAW,CAAC,YAAY,CAAC,CAAC,CAAC,GAAG,wBAAgB,CAAA;IAClD,CAAC,CAAC,CAAA;IACF,OAAO,WAAW,CAAA;AACtB,CAAC,CAAA;AAED,SAAgB,4BAA4B,CACxC,WAAoC,EACpC,UAAkB,EAClB,MAAc,EACd,EAAc;IAEd,IAAI,WAAW,IAAI,IAAA,0BAAY,EAAC,UAAU,EAAE,EAAE,CAAC,EAAE,CAAC;QAC9C,MAAM,WAAW,GAAG,WAAW,CAAC,WAAW,CAAA;QAC3C,MAAM,EAAE,IAAI,EAAE,GAAG,WAAW,CAAA;QAC5B,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,sEAAsE,CAAC,CAAA;QAC1F,MAAM,CAAC,IAAI,CACP,mDAAmD,IAAI,2GA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AC,cAAsB,EAAE,WAAmB,EAAE,QAAkB;IAC/F,kFAAkF;IAClF,MAAM,OAAO,GAAG,MAAM,IAAA,yBAAc,EAAC,cAAc,EAAE,kBAAI,CAAC,IAAI,CAAC,WAAW,EAAE,cAAc,CAAC,EAAE,QAAQ,CAAC,CAAA;IACtG,OAAO,OAAO,EAAE,WAAW,EAAE,OAAO,IAAI,wBAAgB,CAAA;AAC5D,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Logger } from '@servicenow/sdk-project';
|
|
2
|
+
import { RollupFs } from '../file-system-adapter/rollup-fs-adapter';
|
|
3
|
+
import { RealPkgJson } from '../types';
|
|
4
|
+
export declare const splitModuleRequest: (request: string) => {
|
|
5
|
+
moduleName: string;
|
|
6
|
+
entry: string;
|
|
7
|
+
};
|
|
8
|
+
export declare function getRealPkgJson(dependencyName: string | undefined, importer: string, fs: RollupFs, logger?: Logger | undefined): Promise<RealPkgJson | undefined>;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.splitModuleRequest = void 0;
|
|
4
|
+
exports.getRealPkgJson = getRealPkgJson;
|
|
5
|
+
const isomorphic_rollup_1 = require("@servicenow/isomorphic-rollup");
|
|
6
|
+
const sdk_project_1 = require("@servicenow/sdk-project");
|
|
7
|
+
const fs_1 = require("./fs");
|
|
8
|
+
const REGEX = /^(@[a-z0-9-~][a-z0-9-._~]*\/)?[a-z0-9-~][a-z0-9-._~]*/;
|
|
9
|
+
const getModuleName = (request = '') => {
|
|
10
|
+
const match = request.match(REGEX);
|
|
11
|
+
return match && match.length && match[0];
|
|
12
|
+
};
|
|
13
|
+
const splitModuleRequest = (request) => {
|
|
14
|
+
const moduleName = getModuleName(request);
|
|
15
|
+
if (!moduleName) {
|
|
16
|
+
return { moduleName: '', entry: '' };
|
|
17
|
+
}
|
|
18
|
+
const entry = sdk_project_1.path.relative(moduleName, request);
|
|
19
|
+
if (!entry) {
|
|
20
|
+
return { moduleName, entry: '' };
|
|
21
|
+
}
|
|
22
|
+
return { moduleName, entry };
|
|
23
|
+
};
|
|
24
|
+
exports.splitModuleRequest = splitModuleRequest;
|
|
25
|
+
async function getRealPkgJson(dependencyName = '', importer, fs, logger) {
|
|
26
|
+
try {
|
|
27
|
+
const resolve = (0, isomorphic_rollup_1.resolver)({ fs, warn: logger?.warn, ignoreExports: true });
|
|
28
|
+
const pkgJsonRequest = `${dependencyName}/package.json`;
|
|
29
|
+
const resolvedPath = await resolve(pkgJsonRequest, importer);
|
|
30
|
+
const pkgJsonPath = resolvedPath?.id;
|
|
31
|
+
let realPkgJson;
|
|
32
|
+
if (pkgJsonPath && (await (0, fs_1.fileExists)(pkgJsonPath, fs))) {
|
|
33
|
+
realPkgJson = JSON.parse(await fs.readFile(pkgJsonPath, undefined));
|
|
34
|
+
if (realPkgJson && realPkgJson?.name === dependencyName) {
|
|
35
|
+
return { packageJson: realPkgJson, path: pkgJsonPath };
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
console.error(`Error fetching package.json for ${dependencyName}:`, error);
|
|
41
|
+
}
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=resolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolver.js","sourceRoot":"","sources":["../../../src/bundle-artifacts/support/resolver.ts"],"names":[],"mappings":";;;AA0BA,wCAuBC;AAjDD,qEAAwD;AACxD,yDAAsD;AAGtD,6BAAiC;AACjC,MAAM,KAAK,GAAG,uDAAuD,CAAA;AAErE,MAAM,aAAa,GAAG,CAAC,OAAO,GAAG,EAAE,EAAE,EAAE;IACnC,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;IAClC,OAAO,KAAK,IAAI,KAAK,CAAC,MAAM,IAAI,KAAK,CAAC,CAA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,CAAC;gBACtD,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,IAAI,EAAE,WAAW,EAAE,CAAA;YAC1D,CAAC;QACL,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,OAAO,CAAC,KAAK,CAAC,mCAAmC,cAAc,GAAG,EAAE,KAAK,CAAC,CAAA;IAC9E,CAAC;IAED,OAAO,SAAS,CAAA;AACpB,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Dependency } from '../types';
|
|
2
|
+
export type FlatObject = {
|
|
3
|
+
[key: string]: string;
|
|
4
|
+
};
|
|
5
|
+
export type PackageJson = {
|
|
6
|
+
name: string | undefined;
|
|
7
|
+
version: string;
|
|
8
|
+
exports: any;
|
|
9
|
+
dependencies: FlatObject;
|
|
10
|
+
};
|
|
11
|
+
export type ModuleOptions = {
|
|
12
|
+
modulePath: string;
|
|
13
|
+
subPath: string | undefined;
|
|
14
|
+
};
|
|
15
|
+
export type RealPkgJson = {
|
|
16
|
+
packageJson: any;
|
|
17
|
+
path: string;
|
|
18
|
+
};
|
|
19
|
+
export type OutFile = {
|
|
20
|
+
name: string;
|
|
21
|
+
path?: string;
|
|
22
|
+
};
|
|
23
|
+
export type DependencyOptions = {
|
|
24
|
+
addDependency: (options: Dependency) => void;
|
|
25
|
+
dependencyId: string | undefined;
|
|
26
|
+
moduleRoot: string;
|
|
27
|
+
cb: ({ moduleName }: {
|
|
28
|
+
moduleName: string;
|
|
29
|
+
}) => void;
|
|
30
|
+
};
|
|
31
|
+
export type HandlerFunction = (id: string, parentId: string | undefined, isResolved: boolean) => boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/bundle-artifacts/support/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Logger } from '@servicenow/sdk-project';
|
|
2
|
+
import { FileSystem } from '@servicenow/sdk-project';
|
|
3
|
+
export type BuildOptions = {
|
|
4
|
+
pkgName: string;
|
|
5
|
+
entryPoint: string[] | undefined;
|
|
6
|
+
outputDir?: string;
|
|
7
|
+
rootDir: string;
|
|
8
|
+
fs: FileSystem;
|
|
9
|
+
options: any;
|
|
10
|
+
logger: Logger;
|
|
11
|
+
useWebFsLoader?: boolean | undefined;
|
|
12
|
+
};
|
|
13
|
+
export type Dependency = {
|
|
14
|
+
dependencyId: string;
|
|
15
|
+
subPaths: string[] | undefined;
|
|
16
|
+
importer?: string | undefined;
|
|
17
|
+
moduleRoot: string;
|
|
18
|
+
};
|
|
19
|
+
export type DependencyDeclaration = {
|
|
20
|
+
[key: string]: string;
|
|
21
|
+
};
|
|
22
|
+
export type DependencyManifest = {
|
|
23
|
+
name: string;
|
|
24
|
+
version: string;
|
|
25
|
+
dependencies: DependencyDeclaration;
|
|
26
|
+
};
|
|
27
|
+
export type DependencyNode = {
|
|
28
|
+
files: string[];
|
|
29
|
+
packagePath: string;
|
|
30
|
+
updatedManifest: DependencyManifest;
|
|
31
|
+
};
|
|
32
|
+
export type RepackageOptions = {
|
|
33
|
+
omitProto?: boolean;
|
|
34
|
+
minify?: boolean;
|
|
35
|
+
};
|
|
36
|
+
export type DependencyBuildOptions = {
|
|
37
|
+
subPaths?: string[] | undefined;
|
|
38
|
+
outDir: string;
|
|
39
|
+
options?: {
|
|
40
|
+
repackage: RepackageOptions;
|
|
41
|
+
};
|
|
42
|
+
dependencyId: string;
|
|
43
|
+
importer: string | undefined;
|
|
44
|
+
requestorModuleRoot: string;
|
|
45
|
+
};
|
|
46
|
+
export type { RealPkgJson, OutFile, FlatObject } from './support/types';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/bundle-artifacts/types.ts"],"names":[],"mappings":""}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { FileSystem, Logger } from '@servicenow/sdk-project';
|
|
2
|
+
export declare const emptyLogger: {
|
|
3
|
+
info: (..._: string[]) => void;
|
|
4
|
+
warn: (..._: string[]) => void;
|
|
5
|
+
error: (..._: string[]) => void;
|
|
6
|
+
debug: (..._: string[]) => void;
|
|
7
|
+
};
|
|
8
|
+
export type RepackOptions = {
|
|
9
|
+
id: string;
|
|
10
|
+
bundle?: boolean;
|
|
11
|
+
minify?: boolean;
|
|
12
|
+
entry: string[] | undefined;
|
|
13
|
+
logger?: Logger;
|
|
14
|
+
workingDir: string;
|
|
15
|
+
fs: FileSystem;
|
|
16
|
+
useWebFsLoader?: boolean | undefined;
|
|
17
|
+
};
|
|
18
|
+
export type { DependencyDeclaration, DependencyManifest, DependencyNode } from './bundle-artifacts/types';
|
|
19
|
+
export declare const build: ({ id, minify, entry, logger, workingDir, fs, useWebFsLoader, }: RepackOptions) => Promise<import("./bundle-artifacts/types").DependencyNode[] | undefined>;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.build = exports.emptyLogger = void 0;
|
|
4
|
+
const index_1 = require("./bundle-artifacts/index");
|
|
5
|
+
const resolver_1 = require("./bundle-artifacts/support/resolver");
|
|
6
|
+
exports.emptyLogger = {
|
|
7
|
+
info: (..._) => { },
|
|
8
|
+
warn: (..._) => { },
|
|
9
|
+
error: (..._) => { },
|
|
10
|
+
debug: (..._) => { },
|
|
11
|
+
};
|
|
12
|
+
const build = async ({ id, minify = false, entry, logger = exports.emptyLogger, workingDir, fs, useWebFsLoader, }) => {
|
|
13
|
+
const treeRoot = await (0, index_1.runBuild)({
|
|
14
|
+
pkgName: (0, resolver_1.splitModuleRequest)(id).moduleName,
|
|
15
|
+
entryPoint: entry,
|
|
16
|
+
options: { repackage: { minify, omitProto: true } },
|
|
17
|
+
rootDir: workingDir,
|
|
18
|
+
logger,
|
|
19
|
+
fs,
|
|
20
|
+
useWebFsLoader,
|
|
21
|
+
});
|
|
22
|
+
logger.info('Done!');
|
|
23
|
+
return treeRoot;
|
|
24
|
+
};
|
|
25
|
+
exports.build = build;
|
|
26
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,oDAAmD;AAEnD,kEAAwE;AAE3D,QAAA,WAAW,GAAG;IACvB,IAAI,EAAE,CAAC,GAAG,CAAW,EAAE,EAAE,GAAE,CAAC;IAC5B,IAAI,EAAE,CAAC,GAAG,CAAW,EAAE,EAAE,GAAE,CAAC;IAC5B,KAAK,EAAE,CAAC,GAAG,CAAW,EAAE,EAAE,GAAE,CAAC;IAC7B,KAAK,EAAE,CAAC,GAAG,CAAW,EAAE,EAAE,GAAE,CAAC;CAChC,CAAA;AAeM,MAAM,KAAK,GAAG,KAAK,EAAE,EACxB,EAAE,EACF,MAAM,GAAG,KAAK,EACd,KAAK,EACL,MAAM,GAAG,mBAAW,EACpB,UAAU,EACV,EAAE,EACF,cAAc,GACF,EAAE,EAAE;IAChB,MAAM,QAAQ,GAAG,MAAM,IAAA,gBAAQ,EAAC;QAC5B,OAAO,EAAE,IAAA,6BAAkB,EAAC,EAAE,CAAC,CAAC,UAAU;QAC1C,UAAU,EAAE,KAAK;QACjB,OAAO,EAAE,EAAE,SAAS,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE;QACnD,OAAO,EAAE,UAAU;QACnB,MAAM;QACN,EAAE;QACF,cAAc;KACjB,CAAC,CAAA;IAEF,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IACpB,OAAO,QAAQ,CAAA;AACnB,CAAC,CAAA;AArBY,QAAA,KAAK,SAqBjB"}
|
package/license
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 ServiceNow Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@servicenow/sdk-repack",
|
|
3
|
+
"version": "2.2.1",
|
|
4
|
+
"description": "Transforms an NPM package into an artifact before provisioning into an instance.",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": "./dist/index.js"
|
|
8
|
+
},
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"files": [
|
|
11
|
+
"dist"
|
|
12
|
+
],
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"@types/lodash": "4.17.7",
|
|
16
|
+
"lodash": "4.17.21"
|
|
17
|
+
},
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@servicenow/isomorphic-rollup": "1.0.2",
|
|
20
|
+
"rollup": "4.22.5",
|
|
21
|
+
"@servicenow/sdk-project": "2.2.1"
|
|
22
|
+
},
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "tsc -b",
|
|
25
|
+
"clean": "tsc -b --clean",
|
|
26
|
+
"lint": "eslint . --ext .ts",
|
|
27
|
+
"prettier:check": "prettier --check --ignore-path=../../.prettierignore .",
|
|
28
|
+
"prettier:write": "prettier --write --ignore-path=../../.prettierignore .",
|
|
29
|
+
"watch": "tsc -b -w",
|
|
30
|
+
"test": "tsc -b tsconfig.test.json && export NODE_OPTIONS=\"--max-old-space-size=8192 --experimental-vm-modules\" && jest --colors --reporters=default --no-cache --logHeapUsage"
|
|
31
|
+
}
|
|
32
|
+
}
|