@softarc/native-federation-esbuild 4.0.0-RC1 → 4.0.0-RC9
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 +2 -0
- package/src/domain.d.ts.map +1 -0
- package/src/domain.js +1 -0
- package/src/index.d.ts +2 -1
- package/src/index.d.ts.map +1 -1
- package/src/index.js +2 -1
- 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 +68 -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/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 +25 -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-RC9",
|
|
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-RC9"
|
|
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"}
|
package/src/domain.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './lib/domain/adapter-config.contract.js';
|
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,aAAa,CAAC"}
|
package/src/index.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export * from './lib/adapter.js';
|
|
1
|
+
export * from './lib/core/esbuild-adapter.js';
|
|
2
|
+
export * from './domain.js';
|
|
@@ -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,EAIf,MAAM,mCAAmC,CAAC;AAG3C,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sCAAsC,CAAC;AAKjF,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,oBAAoB,GAAG,cAAc,CAyGjF"}
|
|
@@ -0,0 +1,68 @@
|
|
|
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
|
+
if (!bundleContextCache.has(name)) {
|
|
14
|
+
throw new Error(`Could not dispose of non-existing build '${name}'`);
|
|
15
|
+
}
|
|
16
|
+
const entry = bundleContextCache.get(name);
|
|
17
|
+
await entry.ctx.dispose();
|
|
18
|
+
bundleContextCache.delete(name);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
// Dispose all contexts
|
|
22
|
+
const disposals = [];
|
|
23
|
+
for (const [, entry] of bundleContextCache) {
|
|
24
|
+
disposals.push(entry.ctx.dispose());
|
|
25
|
+
}
|
|
26
|
+
bundleContextCache.clear();
|
|
27
|
+
await Promise.all(disposals);
|
|
28
|
+
await esbuild.stop();
|
|
29
|
+
};
|
|
30
|
+
const setup = async (name, options) => {
|
|
31
|
+
const { entryPoints, external, outdir, hash, dev = false, platform = 'browser', tsConfigPath, isMappingOrExposed, } = options;
|
|
32
|
+
if (bundleContextCache.has(name)) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const esbuildPlatform = platform === 'node' ? 'node' : 'browser';
|
|
36
|
+
const ctx = isMappingOrExposed
|
|
37
|
+
? await createSourceCodeEsbuildContext(entryPoints, external, outdir, config, dev, hash, esbuildPlatform, tsConfigPath)
|
|
38
|
+
: await createNodeModulesEsbuildContext(entryPoints, external, outdir, config, dev, hash, esbuildPlatform);
|
|
39
|
+
bundleContextCache.set(name, {
|
|
40
|
+
ctx,
|
|
41
|
+
outdir,
|
|
42
|
+
dev,
|
|
43
|
+
name,
|
|
44
|
+
isMappingOrExposed,
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
const build = async (name, opts = {}) => {
|
|
48
|
+
const bundleContext = bundleContextCache.get(name);
|
|
49
|
+
if (!bundleContext) {
|
|
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
|
+
try {
|
|
56
|
+
const result = await bundleContext.ctx.rebuild();
|
|
57
|
+
const writtenFiles = writeResult(result, bundleContext.outdir);
|
|
58
|
+
return writtenFiles.map(fileName => ({ fileName }));
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
if (opts?.signal?.aborted && error instanceof Error && error.message.includes('canceled')) {
|
|
62
|
+
throw new AbortedError('[build] ESBuild rebuild was canceled.');
|
|
63
|
+
}
|
|
64
|
+
throw error;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
return { setup, build, dispose };
|
|
68
|
+
}
|
|
@@ -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 @@
|
|
|
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,CAsB/B"}
|
|
@@ -0,0 +1,25 @@
|
|
|
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
|
+
outdir,
|
|
11
|
+
entryNames: hash ? '[name]-[hash]' : '[name]',
|
|
12
|
+
external,
|
|
13
|
+
loader: config.loader,
|
|
14
|
+
bundle: true,
|
|
15
|
+
sourcemap: dev,
|
|
16
|
+
minify: !dev,
|
|
17
|
+
format: 'esm',
|
|
18
|
+
splitting: false, // Todo: support splitting
|
|
19
|
+
target: ['esnext'],
|
|
20
|
+
platform,
|
|
21
|
+
tsconfig: tsConfigPath,
|
|
22
|
+
plugins: [...config.plugins],
|
|
23
|
+
resolveExtensions: ['.ts', '.tsx', '.mjs', '.js', '.cjs'],
|
|
24
|
+
});
|
|
25
|
+
}
|
|
@@ -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
|