@softarc/native-federation-esbuild 4.0.0-RC1 → 4.0.0-RC10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +9 -7
- package/src/domain.d.ts +4 -0
- package/src/domain.d.ts.map +1 -0
- package/src/domain.js +3 -0
- package/src/index.d.ts +4 -1
- package/src/index.d.ts.map +1 -1
- package/src/index.js +4 -1
- package/src/lib/core/builder.d.ts +10 -0
- package/src/lib/core/builder.d.ts.map +1 -0
- package/src/lib/core/builder.js +102 -0
- package/src/lib/core/esbuild-adapter.d.ts +4 -0
- package/src/lib/core/esbuild-adapter.d.ts.map +1 -0
- package/src/lib/core/esbuild-adapter.js +89 -0
- package/src/lib/core/normalize-options.d.ts +3 -0
- package/src/lib/core/normalize-options.d.ts.map +1 -0
- package/src/lib/core/normalize-options.js +29 -0
- package/src/lib/domain/adapter-config.contract.d.ts +13 -0
- package/src/lib/domain/adapter-config.contract.d.ts.map +1 -0
- package/src/lib/domain/adapter-config.contract.js +1 -0
- package/src/lib/domain/adapter-context.contract.d.ts +7 -0
- package/src/lib/domain/adapter-context.contract.d.ts.map +1 -0
- package/src/lib/domain/adapter-context.contract.js +1 -0
- package/src/lib/domain/builder-config.contract.d.ts +32 -0
- package/src/lib/domain/builder-config.contract.d.ts.map +1 -0
- package/src/lib/domain/builder-config.contract.js +1 -0
- package/src/lib/utils/collect-exports.d.ts.map +1 -0
- package/src/lib/utils/index.d.ts +6 -0
- package/src/lib/utils/index.d.ts.map +1 -0
- package/src/lib/utils/index.js +5 -0
- package/src/lib/utils/node-modules-bundler.d.ts +5 -0
- package/src/lib/utils/node-modules-bundler.d.ts.map +1 -0
- package/src/lib/utils/node-modules-bundler.js +56 -0
- package/src/lib/utils/react-replacements.d.ts +3 -0
- package/src/lib/utils/react-replacements.d.ts.map +1 -0
- package/src/lib/utils/source-code-bundler.d.ts +5 -0
- package/src/lib/utils/source-code-bundler.d.ts.map +1 -0
- package/src/lib/utils/source-code-bundler.js +26 -0
- package/src/lib/utils/write-result.d.ts +3 -0
- package/src/lib/utils/write-result.d.ts.map +1 -0
- package/src/lib/utils/write-result.js +13 -0
- package/src/lib/adapter.d.ts +0 -17
- package/src/lib/adapter.d.ts.map +0 -1
- package/src/lib/adapter.js +0 -140
- package/src/lib/collect-exports.d.ts.map +0 -1
- package/src/lib/react-replacements.d.ts +0 -3
- package/src/lib/react-replacements.d.ts.map +0 -1
- /package/src/lib/{collect-exports.d.ts → utils/collect-exports.d.ts} +0 -0
- /package/src/lib/{collect-exports.js → utils/collect-exports.js} +0 -0
- /package/src/lib/{react-replacements.js → utils/react-replacements.js} +0 -0
package/package.json
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@softarc/native-federation-esbuild",
|
|
3
|
-
"version": "4.0.0-
|
|
3
|
+
"version": "4.0.0-RC10",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"esbuild": "^0.19.
|
|
8
|
-
"
|
|
9
|
-
"@
|
|
10
|
-
"acorn": "^8.15.0",
|
|
11
|
-
"rollup": "^4.56.0",
|
|
12
|
-
"rollup-plugin-node-externals": "^8.1.2"
|
|
7
|
+
"@chialab/esbuild-plugin-commonjs": "^0.19.1",
|
|
8
|
+
"acorn": "^8.16.0",
|
|
9
|
+
"@softarc/native-federation": "~4.0.0"
|
|
13
10
|
},
|
|
14
11
|
"homepage": "https://github.com/native-federation/esbuild-adapter",
|
|
15
12
|
"repository": {
|
|
@@ -22,6 +19,11 @@
|
|
|
22
19
|
"types": "./src/index.d.ts",
|
|
23
20
|
"import": "./src/index.js",
|
|
24
21
|
"default": "./src/index.js"
|
|
22
|
+
},
|
|
23
|
+
"./config": {
|
|
24
|
+
"types": "./src/config.d.ts",
|
|
25
|
+
"import": "./src/config.js",
|
|
26
|
+
"default": "./src/config.js"
|
|
25
27
|
}
|
|
26
28
|
},
|
|
27
29
|
"files": [
|
package/src/domain.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"domain.d.ts","sourceRoot":"","sources":["../../src/domain.ts"],"names":[],"mappings":"AAAA,cAAc,yCAAyC,CAAC;AACxD,cAAc,0CAA0C,CAAC;AACzD,cAAc,yCAAyC,CAAC"}
|
package/src/domain.js
ADDED
package/src/index.d.ts
CHANGED
package/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC;AAC9C,cAAc,uBAAuB,CAAC;AACtC,cAAc,iCAAiC,CAAC;AAChD,cAAc,aAAa,CAAC"}
|
package/src/index.js
CHANGED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type FederationInfo } from '@softarc/native-federation';
|
|
2
|
+
import type { EsBuildBuilderOptions, NormalizedEsBuildBuilderOptions } from '../domain/builder-config.contract.js';
|
|
3
|
+
export interface EsBuildBuilder {
|
|
4
|
+
federationInfo: FederationInfo;
|
|
5
|
+
externals: string[];
|
|
6
|
+
options: NormalizedEsBuildBuilderOptions;
|
|
7
|
+
close(): Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
export declare function runEsBuildBuilder(federationConfigPath: string, rawOptions: EsBuildBuilderOptions): Promise<EsBuildBuilder>;
|
|
10
|
+
//# sourceMappingURL=builder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../../../../src/lib/core/builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,cAAc,EAKpB,MAAM,4BAA4B,CAAC;AAWpC,OAAO,KAAK,EACV,qBAAqB,EACrB,+BAA+B,EAChC,MAAM,sCAAsC,CAAC;AAK9C,MAAM,WAAW,cAAc;IAC7B,cAAc,EAAE,cAAc,CAAC;IAC/B,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,OAAO,EAAE,+BAA+B,CAAC;IACzC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AAED,wBAAsB,iBAAiB,CACrC,oBAAoB,EAAE,MAAM,EAC5B,UAAU,EAAE,qBAAqB,GAChC,OAAO,CAAC,cAAc,CAAC,CA4GzB"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { buildForFederation, createFederationCache, getExternals, normalizeFederationOptions, rebuildForFederation, setBuildAdapter, } from '@softarc/native-federation';
|
|
2
|
+
import { AbortedError, createNfWatcher, logger, RebuildQueue, setLogLevel, syncNfFileWatcher, } from '@softarc/native-federation/internal';
|
|
3
|
+
import { createEsBuildAdapter } from './esbuild-adapter.js';
|
|
4
|
+
import { normalizeBuilderOptions } from './normalize-options.js';
|
|
5
|
+
export async function runEsBuildBuilder(federationConfigPath, rawOptions) {
|
|
6
|
+
const options = normalizeBuilderOptions(rawOptions);
|
|
7
|
+
setLogLevel(options.verbose ? 'verbose' : 'info');
|
|
8
|
+
const adapter = createEsBuildAdapter(options.adapterConfig);
|
|
9
|
+
setBuildAdapter(adapter);
|
|
10
|
+
const bundlerCache = new Map();
|
|
11
|
+
const normalized = await normalizeFederationOptions({
|
|
12
|
+
projectName: options.projectName,
|
|
13
|
+
workspaceRoot: options.workspaceRoot,
|
|
14
|
+
outputPath: options.outputPath,
|
|
15
|
+
federationConfig: federationConfigPath,
|
|
16
|
+
tsConfig: options.tsConfig,
|
|
17
|
+
verbose: options.verbose,
|
|
18
|
+
watch: options.watch,
|
|
19
|
+
dev: options.dev,
|
|
20
|
+
entryPoints: options.entryPoints,
|
|
21
|
+
packageJson: options.packageJson,
|
|
22
|
+
cacheExternalArtifacts: options.cacheExternalArtifacts,
|
|
23
|
+
}, createFederationCache(options.cachePath, bundlerCache));
|
|
24
|
+
const externals = getExternals(normalized.config);
|
|
25
|
+
let federationInfo;
|
|
26
|
+
try {
|
|
27
|
+
federationInfo = await buildForFederation(normalized.config, normalized.options, externals);
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
logger.error(error?.message ?? 'Building the federation artifacts failed');
|
|
31
|
+
await adapter.dispose();
|
|
32
|
+
throw error;
|
|
33
|
+
}
|
|
34
|
+
if (!options.watch) {
|
|
35
|
+
return {
|
|
36
|
+
federationInfo,
|
|
37
|
+
externals,
|
|
38
|
+
options,
|
|
39
|
+
close: () => adapter.dispose(),
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
const rebuildQueue = new RebuildQueue();
|
|
43
|
+
const pendingChanges = new Set();
|
|
44
|
+
let closed = false;
|
|
45
|
+
const watcher = createNfWatcher({
|
|
46
|
+
onChange: changedPath => {
|
|
47
|
+
if (closed)
|
|
48
|
+
return;
|
|
49
|
+
pendingChanges.add(changedPath);
|
|
50
|
+
void triggerRebuild();
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
syncNfFileWatcher(watcher, bundlerCache);
|
|
54
|
+
async function triggerRebuild() {
|
|
55
|
+
await rebuildQueue.track(async (signal) => {
|
|
56
|
+
try {
|
|
57
|
+
await abortableDelay(Math.max(10, options.rebuildDelay), signal);
|
|
58
|
+
if (signal.aborted) {
|
|
59
|
+
throw new AbortedError('[builder] Aborted before rebuild');
|
|
60
|
+
}
|
|
61
|
+
const files = [...pendingChanges];
|
|
62
|
+
pendingChanges.clear();
|
|
63
|
+
federationInfo = await rebuildForFederation(normalized.config, normalized.options, externals, files, signal);
|
|
64
|
+
syncNfFileWatcher(watcher, bundlerCache);
|
|
65
|
+
logger.info('Federation rebuild done.');
|
|
66
|
+
return { success: true };
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
if (error instanceof AbortedError) {
|
|
70
|
+
logger.verbose('Rebuild was canceled: ' + error.message);
|
|
71
|
+
return { success: false, cancelled: true };
|
|
72
|
+
}
|
|
73
|
+
logger.error('Federation rebuild failed!');
|
|
74
|
+
if (options.verbose)
|
|
75
|
+
console.error(error);
|
|
76
|
+
return { success: false };
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
get federationInfo() {
|
|
82
|
+
return federationInfo;
|
|
83
|
+
},
|
|
84
|
+
externals,
|
|
85
|
+
options,
|
|
86
|
+
async close() {
|
|
87
|
+
closed = true;
|
|
88
|
+
rebuildQueue.dispose();
|
|
89
|
+
await watcher.close();
|
|
90
|
+
await adapter.dispose();
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
function abortableDelay(ms, signal) {
|
|
95
|
+
return new Promise((resolve, reject) => {
|
|
96
|
+
const timeout = setTimeout(resolve, ms);
|
|
97
|
+
signal.addEventListener('abort', () => {
|
|
98
|
+
clearTimeout(timeout);
|
|
99
|
+
reject(new AbortedError('[builder] Debounce canceled'));
|
|
100
|
+
}, { once: true });
|
|
101
|
+
});
|
|
102
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { NFBuildAdapter } from '@softarc/native-federation/domain';
|
|
2
|
+
import type { EsBuildAdapterConfig } from '../domain/adapter-config.contract.js';
|
|
3
|
+
export declare function createEsBuildAdapter(config: EsBuildAdapterConfig): NFBuildAdapter;
|
|
4
|
+
//# sourceMappingURL=esbuild-adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"esbuild-adapter.d.ts","sourceRoot":"","sources":["../../../../src/lib/core/esbuild-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EAGf,MAAM,mCAAmC,CAAC;AAG3C,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sCAAsC,CAAC;AAMjF,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,oBAAoB,GAAG,cAAc,CAiIjF"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { AbortedError } from '@softarc/native-federation/internal';
|
|
2
|
+
import * as esbuild from 'esbuild';
|
|
3
|
+
import { writeResult } from '../utils/write-result.js';
|
|
4
|
+
import { createSourceCodeEsbuildContext } from '../utils/source-code-bundler.js';
|
|
5
|
+
import { createNodeModulesEsbuildContext } from '../utils/node-modules-bundler.js';
|
|
6
|
+
export function createEsBuildAdapter(config) {
|
|
7
|
+
if (!config.compensateExports) {
|
|
8
|
+
config.compensateExports = [new RegExp('/react/')];
|
|
9
|
+
}
|
|
10
|
+
const bundleContextCache = new Map();
|
|
11
|
+
const dispose = async (name) => {
|
|
12
|
+
if (name) {
|
|
13
|
+
const entry = bundleContextCache.get(name);
|
|
14
|
+
if (!entry) {
|
|
15
|
+
throw new Error(`Could not dispose of non-existing build '${name}'`);
|
|
16
|
+
}
|
|
17
|
+
await entry.ctx.dispose();
|
|
18
|
+
bundleContextCache.delete(name);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const disposals = [];
|
|
22
|
+
for (const [, entry] of bundleContextCache) {
|
|
23
|
+
disposals.push(entry.ctx.dispose());
|
|
24
|
+
}
|
|
25
|
+
bundleContextCache.clear();
|
|
26
|
+
await Promise.all(disposals);
|
|
27
|
+
await esbuild.stop();
|
|
28
|
+
};
|
|
29
|
+
const setup = async (name, options) => {
|
|
30
|
+
const { entryPoints, external, outdir, hash, dev = false, platform = 'browser', tsConfigPath, isMappingOrExposed, cache, } = options;
|
|
31
|
+
if (bundleContextCache.has(name)) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const esbuildPlatform = platform === 'node' ? 'node' : 'browser';
|
|
35
|
+
const ctx = isMappingOrExposed
|
|
36
|
+
? await createSourceCodeEsbuildContext(entryPoints, external, outdir, config, dev, hash, esbuildPlatform, tsConfigPath)
|
|
37
|
+
: await createNodeModulesEsbuildContext(entryPoints, external, outdir, config, dev, hash, esbuildPlatform);
|
|
38
|
+
bundleContextCache.set(name, {
|
|
39
|
+
ctx,
|
|
40
|
+
outdir,
|
|
41
|
+
dev,
|
|
42
|
+
name,
|
|
43
|
+
isMappingOrExposed,
|
|
44
|
+
bundlerCache: cache?.bundlerCache,
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
const build = async (name, opts = {}) => {
|
|
48
|
+
const entry = bundleContextCache.get(name);
|
|
49
|
+
if (!entry) {
|
|
50
|
+
throw new Error(`No context found for build "${name}". Call setup() first.`);
|
|
51
|
+
}
|
|
52
|
+
if (opts.signal?.aborted) {
|
|
53
|
+
throw new AbortedError('[build] Aborted before rebuild');
|
|
54
|
+
}
|
|
55
|
+
if (opts.modifiedFiles && entry.bundlerCache) {
|
|
56
|
+
for (const file of opts.modifiedFiles)
|
|
57
|
+
entry.bundlerCache.delete(file);
|
|
58
|
+
}
|
|
59
|
+
const cancelBuild = () => {
|
|
60
|
+
try {
|
|
61
|
+
entry.ctx.cancel();
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
// noop — context may already be cancelled/disposed
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
opts.signal?.addEventListener('abort', cancelBuild, { once: true });
|
|
68
|
+
try {
|
|
69
|
+
const result = await entry.ctx.rebuild();
|
|
70
|
+
const writtenFiles = writeResult(result, entry.outdir);
|
|
71
|
+
if (entry.bundlerCache && result.metafile) {
|
|
72
|
+
for (const input of Object.keys(result.metafile.inputs)) {
|
|
73
|
+
entry.bundlerCache.set(input, null);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return writtenFiles.map(fileName => ({ fileName }));
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
if (opts.signal?.aborted && error instanceof Error && error.message.includes('canceled')) {
|
|
80
|
+
throw new AbortedError('[build] ESBuild rebuild was canceled.');
|
|
81
|
+
}
|
|
82
|
+
throw error;
|
|
83
|
+
}
|
|
84
|
+
finally {
|
|
85
|
+
opts.signal?.removeEventListener('abort', cancelBuild);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
return { setup, build, dispose };
|
|
89
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { EsBuildBuilderOptions, NormalizedEsBuildBuilderOptions } from '../domain/builder-config.contract.js';
|
|
2
|
+
export declare function normalizeBuilderOptions(options: EsBuildBuilderOptions): NormalizedEsBuildBuilderOptions;
|
|
3
|
+
//# sourceMappingURL=normalize-options.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalize-options.d.ts","sourceRoot":"","sources":["../../../../src/lib/core/normalize-options.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,qBAAqB,EACrB,+BAA+B,EAChC,MAAM,sCAAsC,CAAC;AAG9C,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,qBAAqB,GAC7B,+BAA+B,CA6BjC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import * as path from 'path';
|
|
2
|
+
import { getDefaultCachePath } from '@softarc/native-federation/internal';
|
|
3
|
+
export function normalizeBuilderOptions(options) {
|
|
4
|
+
if (!options.outputPath) {
|
|
5
|
+
throw new Error('[esbuild-builder] outputPath is required');
|
|
6
|
+
}
|
|
7
|
+
const workspaceRoot = options.workspaceRoot
|
|
8
|
+
? path.resolve(process.cwd(), options.workspaceRoot)
|
|
9
|
+
: process.cwd();
|
|
10
|
+
const tsConfig = options.tsConfig ?? 'tsconfig.json';
|
|
11
|
+
const cachePath = options.cachePath
|
|
12
|
+
? path.join(workspaceRoot, options.cachePath)
|
|
13
|
+
: getDefaultCachePath(workspaceRoot);
|
|
14
|
+
return {
|
|
15
|
+
workspaceRoot,
|
|
16
|
+
outputPath: options.outputPath,
|
|
17
|
+
tsConfig,
|
|
18
|
+
cachePath,
|
|
19
|
+
projectName: options.projectName,
|
|
20
|
+
entryPoints: options.entryPoints,
|
|
21
|
+
packageJson: options.packageJson,
|
|
22
|
+
dev: !!options.dev,
|
|
23
|
+
watch: !!options.watch,
|
|
24
|
+
verbose: !!options.verbose,
|
|
25
|
+
rebuildDelay: options.rebuildDelay ?? 50,
|
|
26
|
+
cacheExternalArtifacts: options.cacheExternalArtifacts !== false,
|
|
27
|
+
adapterConfig: options.adapterConfig ?? { plugins: [] },
|
|
28
|
+
};
|
|
29
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type * as esbuild from 'esbuild';
|
|
2
|
+
export type ReplacementConfig = {
|
|
3
|
+
file: string;
|
|
4
|
+
};
|
|
5
|
+
export interface EsBuildAdapterConfig {
|
|
6
|
+
plugins: esbuild.Plugin[];
|
|
7
|
+
fileReplacements?: Record<string, string | ReplacementConfig>;
|
|
8
|
+
compensateExports?: RegExp[];
|
|
9
|
+
loader?: {
|
|
10
|
+
[ext: string]: esbuild.Loader;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=adapter-config.contract.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter-config.contract.d.ts","sourceRoot":"","sources":["../../../../src/lib/domain/adapter-config.contract.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,OAAO,MAAM,SAAS,CAAC;AACxC,MAAM,MAAM,iBAAiB,GAAG;IAC9B,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC;IAC1B,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,iBAAiB,CAAC,CAAC;IAC9D,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC7B,MAAM,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAA;KAAE,CAAC;CAC5C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { NFBuildAdapterContext } from '@softarc/native-federation';
|
|
2
|
+
import type * as esbuild from 'esbuild';
|
|
3
|
+
export type EsbuildBundlerCache = Map<string, unknown>;
|
|
4
|
+
export interface CachedContext extends NFBuildAdapterContext<esbuild.BuildContext> {
|
|
5
|
+
bundlerCache: EsbuildBundlerCache | undefined;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=adapter-context.contract.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter-context.contract.d.ts","sourceRoot":"","sources":["../../../../src/lib/domain/adapter-context.contract.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACxE,OAAO,KAAK,KAAK,OAAO,MAAM,SAAS,CAAC;AAExC,MAAM,MAAM,mBAAmB,GAAG,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAEvD,MAAM,WAAW,aAAc,SAAQ,qBAAqB,CAAC,OAAO,CAAC,YAAY,CAAC;IAChF,YAAY,EAAE,mBAAmB,GAAG,SAAS,CAAC;CAC/C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { EsBuildAdapterConfig } from './adapter-config.contract.js';
|
|
2
|
+
export interface EsBuildBuilderOptions {
|
|
3
|
+
workspaceRoot?: string;
|
|
4
|
+
outputPath: string;
|
|
5
|
+
tsConfig?: string;
|
|
6
|
+
cachePath?: string;
|
|
7
|
+
projectName?: string;
|
|
8
|
+
entryPoints?: string[];
|
|
9
|
+
packageJson?: string;
|
|
10
|
+
dev?: boolean;
|
|
11
|
+
watch?: boolean;
|
|
12
|
+
verbose?: boolean;
|
|
13
|
+
rebuildDelay?: number;
|
|
14
|
+
cacheExternalArtifacts?: boolean;
|
|
15
|
+
adapterConfig?: EsBuildAdapterConfig;
|
|
16
|
+
}
|
|
17
|
+
export interface NormalizedEsBuildBuilderOptions {
|
|
18
|
+
workspaceRoot: string;
|
|
19
|
+
outputPath: string;
|
|
20
|
+
cachePath: string;
|
|
21
|
+
tsConfig: string;
|
|
22
|
+
projectName?: string;
|
|
23
|
+
entryPoints?: string[];
|
|
24
|
+
packageJson?: string;
|
|
25
|
+
dev: boolean;
|
|
26
|
+
watch: boolean;
|
|
27
|
+
verbose: boolean;
|
|
28
|
+
rebuildDelay: number;
|
|
29
|
+
cacheExternalArtifacts: boolean;
|
|
30
|
+
adapterConfig: EsBuildAdapterConfig;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=builder-config.contract.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builder-config.contract.d.ts","sourceRoot":"","sources":["../../../../src/lib/domain/builder-config.contract.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AAEzE,MAAM,WAAW,qBAAqB;IACpC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,sBAAsB,CAAC,EAAE,OAAO,CAAC;IACjC,aAAa,CAAC,EAAE,oBAAoB,CAAC;CACtC;AAED,MAAM,WAAW,+BAA+B;IAC9C,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,GAAG,EAAE,OAAO,CAAC;IACb,KAAK,EAAE,OAAO,CAAC;IACf,OAAO,EAAE,OAAO,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,sBAAsB,EAAE,OAAO,CAAC;IAChC,aAAa,EAAE,oBAAoB,CAAC;CACrC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collect-exports.d.ts","sourceRoot":"","sources":["../../../../src/lib/utils/collect-exports.ts"],"names":[],"mappings":"AAQA,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM;;;;;EAoD1C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/lib/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,0BAA0B,CAAC;AACzC,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import * as esbuild from 'esbuild';
|
|
2
|
+
import type { EntryPoint } from '@softarc/native-federation/domain';
|
|
3
|
+
import type { EsBuildAdapterConfig } from '../domain/adapter-config.contract.js';
|
|
4
|
+
export declare function createNodeModulesEsbuildContext(entryPoints: EntryPoint[], external: string[], outdir: string, config: EsBuildAdapterConfig, dev: boolean, hash: boolean, platform: 'browser' | 'node'): Promise<esbuild.BuildContext>;
|
|
5
|
+
//# sourceMappingURL=node-modules-bundler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-modules-bundler.d.ts","sourceRoot":"","sources":["../../../../src/lib/utils/node-modules-bundler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAEnC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAC;AACpE,OAAO,KAAK,EAAE,oBAAoB,EAAqB,MAAM,sCAAsC,CAAC;AAEpG,wBAAsB,+BAA+B,CACnD,WAAW,EAAE,UAAU,EAAE,EACzB,QAAQ,EAAE,MAAM,EAAE,EAClB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,oBAAoB,EAC5B,GAAG,EAAE,OAAO,EACZ,IAAI,EAAE,OAAO,EACb,QAAQ,EAAE,SAAS,GAAG,MAAM,GAC3B,OAAO,CAAC,OAAO,CAAC,YAAY,CAAC,CAmC/B"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import * as esbuild from 'esbuild';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
export async function createNodeModulesEsbuildContext(entryPoints, external, outdir, config, dev, hash, platform) {
|
|
4
|
+
const env = dev ? 'development' : 'production';
|
|
5
|
+
// Apply file replacements to entry points
|
|
6
|
+
if (config.fileReplacements) {
|
|
7
|
+
const normalizedReplacements = normalize(config.fileReplacements);
|
|
8
|
+
for (const entryPoint of entryPoints) {
|
|
9
|
+
entryPoint.fileName = replaceEntryPoint(entryPoint.fileName, normalizedReplacements);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
const commonjsPluginModule = await import('@chialab/esbuild-plugin-commonjs');
|
|
13
|
+
const commonjsPlugin = commonjsPluginModule.default;
|
|
14
|
+
return esbuild.context({
|
|
15
|
+
entryPoints: entryPoints.map((ep) => ({
|
|
16
|
+
in: ep.fileName,
|
|
17
|
+
out: path.parse(ep.outName).name,
|
|
18
|
+
})),
|
|
19
|
+
write: false,
|
|
20
|
+
outdir,
|
|
21
|
+
entryNames: hash ? '[name]-[hash]' : '[name]',
|
|
22
|
+
external,
|
|
23
|
+
bundle: true,
|
|
24
|
+
sourcemap: dev,
|
|
25
|
+
minify: !dev,
|
|
26
|
+
format: 'esm',
|
|
27
|
+
splitting: false, // Todo: support splitting
|
|
28
|
+
platform,
|
|
29
|
+
plugins: [commonjsPlugin()],
|
|
30
|
+
define: {
|
|
31
|
+
'process.env.NODE_ENV': `"${env}"`,
|
|
32
|
+
},
|
|
33
|
+
resolveExtensions: ['.mjs', '.js', '.cjs'],
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
function normalize(config) {
|
|
37
|
+
const result = {};
|
|
38
|
+
for (const key in config) {
|
|
39
|
+
if (typeof config[key] === 'string') {
|
|
40
|
+
result[key] = {
|
|
41
|
+
file: config[key],
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
result[key] = config[key];
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return result;
|
|
49
|
+
}
|
|
50
|
+
function replaceEntryPoint(entryPoint, fileReplacements) {
|
|
51
|
+
entryPoint = entryPoint.replace(/\\/g, '/');
|
|
52
|
+
for (const key in fileReplacements) {
|
|
53
|
+
entryPoint = entryPoint.replace(new RegExp(`${key}$`), fileReplacements[key].file);
|
|
54
|
+
}
|
|
55
|
+
return entryPoint;
|
|
56
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react-replacements.d.ts","sourceRoot":"","sources":["../../../../src/lib/utils/react-replacements.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;AAE9E,eAAO,MAAM,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CA6B/E,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import * as esbuild from 'esbuild';
|
|
2
|
+
import type { EntryPoint } from '@softarc/native-federation/domain';
|
|
3
|
+
import type { EsBuildAdapterConfig } from '../domain/adapter-config.contract.js';
|
|
4
|
+
export declare function createSourceCodeEsbuildContext(entryPoints: EntryPoint[], external: string[], outdir: string, config: EsBuildAdapterConfig, dev: boolean, hash: boolean, platform: 'browser' | 'node', tsConfigPath?: string): Promise<esbuild.BuildContext>;
|
|
5
|
+
//# sourceMappingURL=source-code-bundler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source-code-bundler.d.ts","sourceRoot":"","sources":["../../../../src/lib/utils/source-code-bundler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAEnC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAC;AACpE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sCAAsC,CAAC;AAEjF,wBAAsB,8BAA8B,CAClD,WAAW,EAAE,UAAU,EAAE,EACzB,QAAQ,EAAE,MAAM,EAAE,EAClB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,oBAAoB,EAC5B,GAAG,EAAE,OAAO,EACZ,IAAI,EAAE,OAAO,EACb,QAAQ,EAAE,SAAS,GAAG,MAAM,EAC5B,YAAY,CAAC,EAAE,MAAM,GACpB,OAAO,CAAC,OAAO,CAAC,YAAY,CAAC,CAuB/B"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import * as esbuild from 'esbuild';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
export async function createSourceCodeEsbuildContext(entryPoints, external, outdir, config, dev, hash, platform, tsConfigPath) {
|
|
4
|
+
return esbuild.context({
|
|
5
|
+
entryPoints: entryPoints.map((ep) => ({
|
|
6
|
+
in: ep.fileName,
|
|
7
|
+
out: path.parse(ep.outName).name,
|
|
8
|
+
})),
|
|
9
|
+
write: false,
|
|
10
|
+
metafile: true,
|
|
11
|
+
outdir,
|
|
12
|
+
entryNames: hash ? '[name]-[hash]' : '[name]',
|
|
13
|
+
external,
|
|
14
|
+
loader: config.loader,
|
|
15
|
+
bundle: true,
|
|
16
|
+
sourcemap: dev,
|
|
17
|
+
minify: !dev,
|
|
18
|
+
format: 'esm',
|
|
19
|
+
splitting: false, // Todo: support splitting
|
|
20
|
+
target: ['esnext'],
|
|
21
|
+
platform,
|
|
22
|
+
tsconfig: tsConfigPath,
|
|
23
|
+
plugins: [...config.plugins],
|
|
24
|
+
resolveExtensions: ['.ts', '.tsx', '.mjs', '.js', '.cjs'],
|
|
25
|
+
});
|
|
26
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"write-result.d.ts","sourceRoot":"","sources":["../../../../src/lib/utils/write-result.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,OAAO,MAAM,SAAS,CAAC;AAExC,wBAAgB,WAAW,CACzB,MAAM,EAAE,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,YAAY,CAAC,EACjD,MAAM,EAAE,MAAM,GACb,MAAM,EAAE,CAWV"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
export function writeResult(result, outdir) {
|
|
4
|
+
const outputFiles = result.outputFiles || [];
|
|
5
|
+
const writtenFiles = [];
|
|
6
|
+
for (const outFile of outputFiles) {
|
|
7
|
+
const fileName = path.basename(outFile.path);
|
|
8
|
+
const filePath = path.join(outdir, fileName);
|
|
9
|
+
fs.writeFileSync(filePath, outFile.contents);
|
|
10
|
+
writtenFiles.push(filePath);
|
|
11
|
+
}
|
|
12
|
+
return writtenFiles;
|
|
13
|
+
}
|
package/src/lib/adapter.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { NFBuildAdapter, NFBuildAdapterOptions, NFBuildAdapterResult } from '@softarc/native-federation/domain';
|
|
2
|
-
import * as esbuild from 'esbuild';
|
|
3
|
-
export declare const esBuildAdapter: NFBuildAdapter;
|
|
4
|
-
export type ReplacementConfig = {
|
|
5
|
-
file: string;
|
|
6
|
-
};
|
|
7
|
-
export interface EsBuildAdapterConfig {
|
|
8
|
-
plugins: esbuild.Plugin[];
|
|
9
|
-
fileReplacements?: Record<string, string | ReplacementConfig>;
|
|
10
|
-
skipRollup?: boolean;
|
|
11
|
-
compensateExports?: RegExp[];
|
|
12
|
-
loader?: {
|
|
13
|
-
[ext: string]: esbuild.Loader;
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
export declare function createEsBuildAdapter(config: EsBuildAdapterConfig): (options: NFBuildAdapterOptions) => Promise<NFBuildAdapterResult[]>;
|
|
17
|
-
//# sourceMappingURL=adapter.d.ts.map
|
package/src/lib/adapter.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../../src/lib/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,qBAAqB,EACrB,oBAAoB,EACrB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAanC,eAAO,MAAM,cAAc,EAAE,cAE3B,CAAC;AAEH,MAAM,MAAM,iBAAiB,GAAG;IAC9B,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC;IAC1B,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,iBAAiB,CAAC,CAAC;IAC9D,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC7B,MAAM,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAA;KAAE,CAAC;CAC5C;AAED,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,oBAAoB,IAKjD,SAAS,qBAAqB,KAAG,OAAO,CAAC,oBAAoB,EAAE,CAAC,CAiD/E"}
|
package/src/lib/adapter.js
DELETED
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
import * as esbuild from 'esbuild';
|
|
2
|
-
import { rollup } from 'rollup';
|
|
3
|
-
import { nodeResolve } from '@rollup/plugin-node-resolve';
|
|
4
|
-
import { nodeExternals } from 'rollup-plugin-node-externals';
|
|
5
|
-
import * as fs from 'fs';
|
|
6
|
-
import path from 'path';
|
|
7
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
8
|
-
const commonjs = require('@rollup/plugin-commonjs');
|
|
9
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
10
|
-
const replace = require('@rollup/plugin-replace');
|
|
11
|
-
export const esBuildAdapter = createEsBuildAdapter({
|
|
12
|
-
plugins: [],
|
|
13
|
-
});
|
|
14
|
-
export function createEsBuildAdapter(config) {
|
|
15
|
-
if (!config.compensateExports) {
|
|
16
|
-
config.compensateExports = [new RegExp('/react/')];
|
|
17
|
-
}
|
|
18
|
-
return async (options) => {
|
|
19
|
-
const { entryPoints, external, outdir, hash } = options;
|
|
20
|
-
// TODO: Do we need to prepare packages anymore as esbuild has evolved?
|
|
21
|
-
for (const entryPoint of entryPoints) {
|
|
22
|
-
const isPkg = entryPoint.fileName.includes('node_modules');
|
|
23
|
-
const pkgName = isPkg ? inferPkgName(entryPoint.fileName) : '';
|
|
24
|
-
const tmpFolder = `node_modules/.tmp/${pkgName}`;
|
|
25
|
-
if (isPkg) {
|
|
26
|
-
await prepareNodePackage(entryPoint.fileName, external, tmpFolder, config, !!options.dev);
|
|
27
|
-
entryPoint.fileName = tmpFolder;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
const ctx = await esbuild.context({
|
|
31
|
-
entryPoints: entryPoints.map(ep => ({
|
|
32
|
-
in: ep.fileName,
|
|
33
|
-
out: path.parse(ep.outName).name,
|
|
34
|
-
})),
|
|
35
|
-
write: false,
|
|
36
|
-
outdir,
|
|
37
|
-
entryNames: hash ? '[name]-[hash]' : '[name]',
|
|
38
|
-
external,
|
|
39
|
-
loader: config.loader,
|
|
40
|
-
bundle: true,
|
|
41
|
-
sourcemap: options.dev,
|
|
42
|
-
minify: !options.dev,
|
|
43
|
-
format: 'esm',
|
|
44
|
-
target: ['esnext'],
|
|
45
|
-
plugins: [...config.plugins],
|
|
46
|
-
});
|
|
47
|
-
const result = await ctx.rebuild();
|
|
48
|
-
const writtenFiles = writeResult(result, outdir);
|
|
49
|
-
ctx.dispose();
|
|
50
|
-
return writtenFiles.map(fileName => ({ fileName }));
|
|
51
|
-
// const normEntryPoint = entryPoint.replace(/\\/g, '/');
|
|
52
|
-
// if (
|
|
53
|
-
// isPkg &&
|
|
54
|
-
// config?.compensateExports?.find((regExp) => regExp.exec(normEntryPoint))
|
|
55
|
-
// ) {
|
|
56
|
-
// logger.verbose('compensate exports for ' + tmpFolder);
|
|
57
|
-
// compensateExports(tmpFolder, outfile);
|
|
58
|
-
// }
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
function writeResult(result, outdir) {
|
|
62
|
-
const outputFiles = result.outputFiles || [];
|
|
63
|
-
const writtenFiles = [];
|
|
64
|
-
for (const outFile of outputFiles) {
|
|
65
|
-
const fileName = path.basename(outFile.path);
|
|
66
|
-
const filePath = path.join(outdir, fileName);
|
|
67
|
-
fs.writeFileSync(filePath, outFile.contents);
|
|
68
|
-
writtenFiles.push(filePath);
|
|
69
|
-
}
|
|
70
|
-
return writtenFiles;
|
|
71
|
-
}
|
|
72
|
-
// TODO: Unused, to delete?
|
|
73
|
-
// function compensateExports(entryPoint: string, outfile?: string): void {
|
|
74
|
-
// const inExports = collectExports(entryPoint);
|
|
75
|
-
// const outExports = outfile ? collectExports(outfile) : inExports;
|
|
76
|
-
//
|
|
77
|
-
// if (!outExports.hasDefaultExport || outExports.hasFurtherExports) {
|
|
78
|
-
// return;
|
|
79
|
-
// }
|
|
80
|
-
// const defaultName = outExports.defaultExportName;
|
|
81
|
-
//
|
|
82
|
-
// let exports = '/*Try to compensate missing exports*/\n\n';
|
|
83
|
-
// for (const exp of inExports.exports) {
|
|
84
|
-
// exports += `let ${exp}$softarc = ${defaultName}.${exp};\n`;
|
|
85
|
-
// exports += `export { ${exp}$softarc as ${exp} };\n`;
|
|
86
|
-
// }
|
|
87
|
-
//
|
|
88
|
-
// const target = outfile ?? entryPoint;
|
|
89
|
-
// fs.appendFileSync(target, exports, 'utf-8');
|
|
90
|
-
// }
|
|
91
|
-
async function prepareNodePackage(entryPoint, external, tmpFolder, config, dev) {
|
|
92
|
-
if (config.fileReplacements) {
|
|
93
|
-
entryPoint = replaceEntryPoint(entryPoint, normalize(config.fileReplacements));
|
|
94
|
-
}
|
|
95
|
-
const env = dev ? 'development' : 'production';
|
|
96
|
-
const result = await rollup({
|
|
97
|
-
input: entryPoint,
|
|
98
|
-
plugins: [
|
|
99
|
-
commonjs(),
|
|
100
|
-
nodeExternals({ include: external }),
|
|
101
|
-
nodeResolve(),
|
|
102
|
-
replace({
|
|
103
|
-
preventAssignment: true,
|
|
104
|
-
values: {
|
|
105
|
-
'process.env.NODE_ENV': `"${env}"`,
|
|
106
|
-
},
|
|
107
|
-
}),
|
|
108
|
-
],
|
|
109
|
-
});
|
|
110
|
-
await result.write({
|
|
111
|
-
format: 'esm',
|
|
112
|
-
file: tmpFolder,
|
|
113
|
-
sourcemap: dev,
|
|
114
|
-
exports: 'named',
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
function inferPkgName(entryPoint) {
|
|
118
|
-
return entryPoint.replace(/.*?node_modules/g, '').replace(/[^A-Za-z0-9.]/g, '_');
|
|
119
|
-
}
|
|
120
|
-
function normalize(config) {
|
|
121
|
-
const result = {};
|
|
122
|
-
for (const key in config) {
|
|
123
|
-
if (typeof config[key] === 'string') {
|
|
124
|
-
result[key] = {
|
|
125
|
-
file: config[key],
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
else {
|
|
129
|
-
result[key] = config[key];
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
return result;
|
|
133
|
-
}
|
|
134
|
-
function replaceEntryPoint(entryPoint, fileReplacements) {
|
|
135
|
-
entryPoint = entryPoint.replace(/\\/g, '/');
|
|
136
|
-
for (const key in fileReplacements) {
|
|
137
|
-
entryPoint = entryPoint.replace(new RegExp(`${key}$`), fileReplacements[key].file);
|
|
138
|
-
}
|
|
139
|
-
return entryPoint;
|
|
140
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"collect-exports.d.ts","sourceRoot":"","sources":["../../../src/lib/collect-exports.ts"],"names":[],"mappings":"AAQA,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM;;;;;EAoD1C"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"react-replacements.d.ts","sourceRoot":"","sources":["../../../src/lib/react-replacements.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAEtD,eAAO,MAAM,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CA6B/E,CAAC"}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|