@storm-software/esbuild 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -8
- package/dist/build.cjs +14 -0
- package/dist/build.d.cts +14 -0
- package/dist/build.d.ts +14 -0
- package/dist/build.js +14 -0
- package/dist/chunk-3C3PXJUM.cjs +28 -0
- package/dist/chunk-3GQAWCBQ.js +13 -0
- package/dist/chunk-4TW4ZA3I.js +52 -0
- package/dist/chunk-5JHKW6MG.js +126 -0
- package/dist/chunk-5S2XTAF2.cjs +337 -0
- package/dist/chunk-A6CGWMV7.cjs +126 -0
- package/dist/chunk-BGYQAVKQ.cjs +13 -0
- package/dist/chunk-DCWECOOS.cjs +22 -0
- package/dist/chunk-ELGZJRET.js +39 -0
- package/dist/chunk-GGNOJ77I.js +0 -0
- package/dist/chunk-LVDPGHWK.js +28 -0
- package/dist/chunk-MTKAAECG.cjs +101 -0
- package/dist/chunk-NVGEXPTG.cjs +39 -0
- package/dist/chunk-PCGRI6Z6.js +101 -0
- package/dist/chunk-RJQ3LCGJ.cjs +14 -0
- package/dist/chunk-RKSGVSXZ.js +22 -0
- package/dist/chunk-SFZRYJZ2.cjs +1 -0
- package/dist/chunk-WLHWKRZB.cjs +52 -0
- package/dist/chunk-YGD5JBOH.js +337 -0
- package/dist/chunk-YIAZ64WG.js +14 -0
- package/dist/config.cjs +9 -0
- package/dist/config.d.cts +15 -0
- package/dist/config.d.ts +15 -0
- package/dist/config.js +9 -0
- package/dist/index.cjs +38 -0
- package/dist/index.d.cts +230 -0
- package/dist/index.d.ts +230 -0
- package/dist/index.js +38 -0
- package/dist/types.cjs +1 -0
- package/dist/types.d.cts +19 -0
- package/dist/types.d.ts +19 -0
- package/dist/types.js +1 -0
- package/package.json +149 -3
- package/index.cjs +0 -19751
- package/index.js +0 -19748
- package/meta.cjs.json +0 -12657
- package/meta.esm.json +0 -12669
package/README.md
CHANGED
|
@@ -40,9 +40,10 @@ This package is part of the <b>⚡Storm-Ops</b> monorepo. The Storm-Ops packages
|
|
|
40
40
|
|
|
41
41
|
<!-- START doctoc -->
|
|
42
42
|
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
|
|
43
|
+
|
|
43
44
|
## Table of Contents
|
|
44
45
|
|
|
45
|
-
- [Storm
|
|
46
|
+
- [Storm ESBuild Package](#storm-esbuild-package)
|
|
46
47
|
- [Installing](#installing)
|
|
47
48
|
- [Building](#building)
|
|
48
49
|
- [Running unit tests](#running-unit-tests)
|
|
@@ -63,23 +64,23 @@ This package is part of the <b>⚡Storm-Ops</b> monorepo. The Storm-Ops packages
|
|
|
63
64
|
|
|
64
65
|
<!-- END header -->
|
|
65
66
|
|
|
66
|
-
# Storm
|
|
67
|
+
# Storm ESBuild Package
|
|
67
68
|
|
|
68
|
-
This package contains the
|
|
69
|
+
This package contains the ESBuild configuration for Storm Software projects.
|
|
69
70
|
|
|
70
71
|
## Installing
|
|
71
72
|
|
|
72
73
|
Using [pnpm](http://pnpm.io):
|
|
73
74
|
|
|
74
75
|
```bash
|
|
75
|
-
pnpm add -D @storm-software/
|
|
76
|
+
pnpm add -D @storm-software/esbuild
|
|
76
77
|
```
|
|
77
78
|
|
|
78
79
|
<details>
|
|
79
80
|
<summary>Using npm</summary>
|
|
80
81
|
|
|
81
82
|
```bash
|
|
82
|
-
npm install -D @storm-software/
|
|
83
|
+
npm install -D @storm-software/esbuild
|
|
83
84
|
```
|
|
84
85
|
|
|
85
86
|
</details>
|
|
@@ -88,18 +89,18 @@ npm install -D @storm-software/prettier
|
|
|
88
89
|
<summary>Using yarn</summary>
|
|
89
90
|
|
|
90
91
|
```bash
|
|
91
|
-
yarn add -D @storm-software/
|
|
92
|
+
yarn add -D @storm-software/esbuild
|
|
92
93
|
```
|
|
93
94
|
|
|
94
95
|
</details>
|
|
95
96
|
|
|
96
97
|
## Building
|
|
97
98
|
|
|
98
|
-
Run `nx build
|
|
99
|
+
Run `nx build esbuild` to build the library.
|
|
99
100
|
|
|
100
101
|
## Running unit tests
|
|
101
102
|
|
|
102
|
-
Run `nx test
|
|
103
|
+
Run `nx test esbuild` to execute the unit tests via [Jest](https://jestjs.io).
|
|
103
104
|
|
|
104
105
|
<!-- START footer -->
|
|
105
106
|
<!-- prettier-ignore-start -->
|
package/dist/build.cjs
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunk5S2XTAF2cjs = require('./chunk-5S2XTAF2.cjs');
|
|
4
|
+
require('./chunk-DCWECOOS.cjs');
|
|
5
|
+
require('./chunk-WLHWKRZB.cjs');
|
|
6
|
+
require('./chunk-A6CGWMV7.cjs');
|
|
7
|
+
require('./chunk-NVGEXPTG.cjs');
|
|
8
|
+
require('./chunk-MTKAAECG.cjs');
|
|
9
|
+
require('./chunk-RJQ3LCGJ.cjs');
|
|
10
|
+
require('./chunk-3C3PXJUM.cjs');
|
|
11
|
+
require('./chunk-BGYQAVKQ.cjs');
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
exports.build = _chunk5S2XTAF2cjs.build;
|
package/dist/build.d.cts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as esbuild from 'esbuild';
|
|
2
|
+
import { ESBuildOptions, ESBuildResolvedOptions } from './types.cjs';
|
|
3
|
+
import '@nx/devkit';
|
|
4
|
+
import 'nx/src/utils/find-workspace-root';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Execution pipeline that applies a set of actions
|
|
8
|
+
*
|
|
9
|
+
* @param options - the build options
|
|
10
|
+
* @returns the build result
|
|
11
|
+
*/
|
|
12
|
+
declare function build(options: ESBuildOptions[]): Promise<(readonly [ESBuildResolvedOptions, esbuild.BuildResult<any>])[]>;
|
|
13
|
+
|
|
14
|
+
export { build };
|
package/dist/build.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as esbuild from 'esbuild';
|
|
2
|
+
import { ESBuildOptions, ESBuildResolvedOptions } from './types.js';
|
|
3
|
+
import '@nx/devkit';
|
|
4
|
+
import 'nx/src/utils/find-workspace-root';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Execution pipeline that applies a set of actions
|
|
8
|
+
*
|
|
9
|
+
* @param options - the build options
|
|
10
|
+
* @returns the build result
|
|
11
|
+
*/
|
|
12
|
+
declare function build(options: ESBuildOptions[]): Promise<(readonly [ESBuildResolvedOptions, esbuild.BuildResult<any>])[]>;
|
|
13
|
+
|
|
14
|
+
export { build };
|
package/dist/build.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import {
|
|
2
|
+
build
|
|
3
|
+
} from "./chunk-YGD5JBOH.js";
|
|
4
|
+
import "./chunk-RKSGVSXZ.js";
|
|
5
|
+
import "./chunk-4TW4ZA3I.js";
|
|
6
|
+
import "./chunk-5JHKW6MG.js";
|
|
7
|
+
import "./chunk-ELGZJRET.js";
|
|
8
|
+
import "./chunk-PCGRI6Z6.js";
|
|
9
|
+
import "./chunk-YIAZ64WG.js";
|
|
10
|
+
import "./chunk-LVDPGHWK.js";
|
|
11
|
+
import "./chunk-3GQAWCBQ.js";
|
|
12
|
+
export {
|
|
13
|
+
build
|
|
14
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunkBGYQAVKQcjs = require('./chunk-BGYQAVKQ.cjs');
|
|
4
|
+
|
|
5
|
+
// src/plugins/fix-imports.ts
|
|
6
|
+
var fixImportsPlugin = {
|
|
7
|
+
name: "storm:fix-imports",
|
|
8
|
+
setup(build) {
|
|
9
|
+
build.onResolve({
|
|
10
|
+
filter: /^spdx-exceptions/
|
|
11
|
+
}, () => {
|
|
12
|
+
return {
|
|
13
|
+
path: _chunkBGYQAVKQcjs.__require.resolve("spdx-exceptions")
|
|
14
|
+
};
|
|
15
|
+
});
|
|
16
|
+
build.onResolve({
|
|
17
|
+
filter: /^spdx-license-ids/
|
|
18
|
+
}, () => {
|
|
19
|
+
return {
|
|
20
|
+
path: _chunkBGYQAVKQcjs.__require.resolve("spdx-license-ids")
|
|
21
|
+
};
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
exports.fixImportsPlugin = fixImportsPlugin;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
4
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
5
|
+
}) : x)(function(x) {
|
|
6
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
7
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
export {
|
|
11
|
+
__name,
|
|
12
|
+
__require
|
|
13
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__name,
|
|
3
|
+
__require
|
|
4
|
+
} from "./chunk-3GQAWCBQ.js";
|
|
5
|
+
|
|
6
|
+
// src/plugins/resolve-paths.ts
|
|
7
|
+
import path from "node:path";
|
|
8
|
+
function resolvePathsConfig(options, cwd) {
|
|
9
|
+
if (options?.compilerOptions?.paths) {
|
|
10
|
+
const paths = Object.entries(options.compilerOptions.paths);
|
|
11
|
+
const resolvedPaths = paths.map(([key, paths2]) => {
|
|
12
|
+
return [
|
|
13
|
+
key,
|
|
14
|
+
paths2.map((v) => path.resolve(cwd, v))
|
|
15
|
+
];
|
|
16
|
+
});
|
|
17
|
+
return Object.fromEntries(resolvedPaths);
|
|
18
|
+
}
|
|
19
|
+
if (options.extends) {
|
|
20
|
+
const extendsPath = path.resolve(cwd, options.extends);
|
|
21
|
+
const extendsDir = path.dirname(extendsPath);
|
|
22
|
+
const extendsConfig = __require(extendsPath);
|
|
23
|
+
return resolvePathsConfig(extendsConfig, extendsDir);
|
|
24
|
+
}
|
|
25
|
+
return [];
|
|
26
|
+
}
|
|
27
|
+
__name(resolvePathsConfig, "resolvePathsConfig");
|
|
28
|
+
var resolvePathsPlugin = {
|
|
29
|
+
name: "storm:resolve-paths",
|
|
30
|
+
setup(build) {
|
|
31
|
+
const parentTsConfig = __require(`${process.cwd()}/${build.initialOptions.tsconfig}`);
|
|
32
|
+
const resolvedTsPaths = resolvePathsConfig(parentTsConfig, process.cwd());
|
|
33
|
+
const packagesRegex = new RegExp(`^(${Object.keys(resolvedTsPaths).join("|")})$`);
|
|
34
|
+
build.onResolve({
|
|
35
|
+
filter: packagesRegex
|
|
36
|
+
}, (args) => {
|
|
37
|
+
if (build.initialOptions.external?.includes(args.path)) {
|
|
38
|
+
return {
|
|
39
|
+
path: args.path,
|
|
40
|
+
external: true
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
path: `${resolvedTsPaths[args.path][0]}/index.ts`
|
|
45
|
+
};
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export {
|
|
51
|
+
resolvePathsPlugin
|
|
52
|
+
};
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import {
|
|
2
|
+
writeLog
|
|
3
|
+
} from "./chunk-YIAZ64WG.js";
|
|
4
|
+
import {
|
|
5
|
+
__name,
|
|
6
|
+
__require
|
|
7
|
+
} from "./chunk-3GQAWCBQ.js";
|
|
8
|
+
|
|
9
|
+
// src/plugins/tsc.ts
|
|
10
|
+
import { hfs } from "@humanfs/node";
|
|
11
|
+
import { Extractor, ExtractorConfig } from "@microsoft/api-extractor";
|
|
12
|
+
import path from "node:path";
|
|
13
|
+
|
|
14
|
+
// src/utilities/run.ts
|
|
15
|
+
import { execaCommand } from "execa";
|
|
16
|
+
function run(command) {
|
|
17
|
+
return execaCommand(command, {
|
|
18
|
+
preferLocal: true,
|
|
19
|
+
shell: true,
|
|
20
|
+
stdio: "inherit"
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
__name(run, "run");
|
|
24
|
+
|
|
25
|
+
// src/plugins/tsc.ts
|
|
26
|
+
function bundleTypeDefinitions(filename, outfile, externals) {
|
|
27
|
+
const { dependencies, peerDependencies, devDependencies } = __require(`${process.cwd()}/package.json`);
|
|
28
|
+
const dependenciesKeys = Object.keys(dependencies ?? {}).flatMap((p) => [
|
|
29
|
+
p,
|
|
30
|
+
getTypeDependencyPackageName(p)
|
|
31
|
+
]);
|
|
32
|
+
const peerDependenciesKeys = Object.keys(peerDependencies ?? {}).flatMap((p) => [
|
|
33
|
+
p,
|
|
34
|
+
getTypeDependencyPackageName(p)
|
|
35
|
+
]);
|
|
36
|
+
const devDependenciesKeys = Object.keys(devDependencies ?? {}).flatMap((p) => [
|
|
37
|
+
p,
|
|
38
|
+
getTypeDependencyPackageName(p)
|
|
39
|
+
]);
|
|
40
|
+
const includeDeps = devDependenciesKeys;
|
|
41
|
+
const excludeDeps = /* @__PURE__ */ new Set([
|
|
42
|
+
...dependenciesKeys,
|
|
43
|
+
...peerDependenciesKeys,
|
|
44
|
+
...externals
|
|
45
|
+
]);
|
|
46
|
+
const bundledPackages = includeDeps.filter((dep) => !excludeDeps.has(dep));
|
|
47
|
+
const extractorConfig = ExtractorConfig.prepare({
|
|
48
|
+
configObject: {
|
|
49
|
+
projectFolder: process.cwd(),
|
|
50
|
+
mainEntryPointFilePath: filename,
|
|
51
|
+
bundledPackages,
|
|
52
|
+
compiler: {
|
|
53
|
+
tsconfigFilePath: path.join(process.cwd(), "tsconfig.build.json"),
|
|
54
|
+
overrideTsconfig: {
|
|
55
|
+
compilerOptions: {
|
|
56
|
+
paths: {}
|
|
57
|
+
// bug with api extract + paths
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
dtsRollup: {
|
|
62
|
+
enabled: true,
|
|
63
|
+
untrimmedFilePath: path.join(process.cwd(), `${outfile}.d.ts`)
|
|
64
|
+
},
|
|
65
|
+
tsdocMetadata: {
|
|
66
|
+
enabled: false
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
packageJsonFullPath: path.join(process.cwd(), "package.json"),
|
|
70
|
+
configObjectFullPath: void 0
|
|
71
|
+
});
|
|
72
|
+
const extractorResult = Extractor.invoke(extractorConfig, {
|
|
73
|
+
showVerboseMessages: true,
|
|
74
|
+
localBuild: true
|
|
75
|
+
});
|
|
76
|
+
if (extractorResult.succeeded === false) {
|
|
77
|
+
writeLog("error", `API Extractor completed with ${extractorResult.errorCount} ${extractorResult.errorCount === 1 ? "error" : "errors"}`);
|
|
78
|
+
throw new Error("API Extractor completed with errors");
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
__name(bundleTypeDefinitions, "bundleTypeDefinitions");
|
|
82
|
+
var tscPlugin = /* @__PURE__ */ __name((emitTypes) => ({
|
|
83
|
+
name: "tscPlugin",
|
|
84
|
+
setup(build) {
|
|
85
|
+
const options = build.initialOptions;
|
|
86
|
+
if (emitTypes === false) return;
|
|
87
|
+
build.onStart(async () => {
|
|
88
|
+
if (process.env.WATCH !== "true" && process.env.DEV !== "true") {
|
|
89
|
+
await run(`tsc --project ${options.tsconfig} --paths null`);
|
|
90
|
+
}
|
|
91
|
+
if (options.bundle && options.outfile && options.entryPoints?.[0].endsWith(".ts")) {
|
|
92
|
+
const tsconfig = __require(`${process.cwd()}/${options.tsconfig}`);
|
|
93
|
+
const typeOutDir = tsconfig?.compilerOptions?.outDir ?? ".";
|
|
94
|
+
const entryPoint = options.entryPoints?.[0].replace(/\.ts$/, "");
|
|
95
|
+
const bundlePath = options.outfile.replace(/\.m?js$/, "");
|
|
96
|
+
let dtsPath;
|
|
97
|
+
if (await hfs.isFile(`${process.cwd()}/${typeOutDir}/${entryPoint}.d.ts`)) {
|
|
98
|
+
dtsPath = `${process.cwd()}/${typeOutDir}/${entryPoint}.d.ts`;
|
|
99
|
+
} else if (await hfs.isFile(`${process.cwd()}/${typeOutDir}/${entryPoint.replace(/^src\//, "")}.d.ts`)) {
|
|
100
|
+
dtsPath = `${process.cwd()}/${typeOutDir}/${entryPoint.replace(/^src\//, "")}.d.ts`;
|
|
101
|
+
}
|
|
102
|
+
const ext = options.format === "esm" ? "d.mts" : "d.ts";
|
|
103
|
+
if (process.env.WATCH !== "true" && process.env.DEV !== "true") {
|
|
104
|
+
bundleTypeDefinitions(dtsPath, bundlePath, options.external ?? []);
|
|
105
|
+
const dtsContents = await hfs.text(`${bundlePath}.d.ts`);
|
|
106
|
+
await hfs.write(`${bundlePath}.${ext}`, dtsContents);
|
|
107
|
+
} else {
|
|
108
|
+
await hfs.write(`${bundlePath}.${ext}`, `export * from '${process.cwd()}/${entryPoint}'`);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
}), "tscPlugin");
|
|
114
|
+
function getTypeDependencyPackageName(npmPackage) {
|
|
115
|
+
if (npmPackage.startsWith("@")) {
|
|
116
|
+
const [scope, name] = npmPackage.split("/");
|
|
117
|
+
return `@types/${scope?.slice(1)}__${name}`;
|
|
118
|
+
}
|
|
119
|
+
return `@types/${npmPackage}`;
|
|
120
|
+
}
|
|
121
|
+
__name(getTypeDependencyPackageName, "getTypeDependencyPackageName");
|
|
122
|
+
|
|
123
|
+
export {
|
|
124
|
+
run,
|
|
125
|
+
tscPlugin
|
|
126
|
+
};
|
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
+
|
|
3
|
+
var _chunkDCWECOOScjs = require('./chunk-DCWECOOS.cjs');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
var _chunkWLHWKRZBcjs = require('./chunk-WLHWKRZB.cjs');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
var _chunkA6CGWMV7cjs = require('./chunk-A6CGWMV7.cjs');
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
var _chunkNVGEXPTGcjs = require('./chunk-NVGEXPTG.cjs');
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
var _chunkMTKAAECGcjs = require('./chunk-MTKAAECG.cjs');
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
var _chunkRJQ3LCGJcjs = require('./chunk-RJQ3LCGJ.cjs');
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
var _chunk3C3PXJUMcjs = require('./chunk-3C3PXJUM.cjs');
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
var _chunkBGYQAVKQcjs = require('./chunk-BGYQAVKQ.cjs');
|
|
25
|
+
|
|
26
|
+
// src/build.ts
|
|
27
|
+
var _node = require('@humanfs/node');
|
|
28
|
+
var _devkit = require('@nx/devkit');
|
|
29
|
+
var _buildablelibsutils = require('@nx/js/src/utils/buildable-libs-utils');
|
|
30
|
+
var _chokidar = require('chokidar');
|
|
31
|
+
var _estoolkit = require('es-toolkit');
|
|
32
|
+
var _compat = require('es-toolkit/compat');
|
|
33
|
+
var _esbuild = require('esbuild'); var esbuild = _interopRequireWildcard(_esbuild);
|
|
34
|
+
var _globby = require('globby');
|
|
35
|
+
var _fs = require('fs');
|
|
36
|
+
var _findworkspaceroot = require('nx/src/utils/find-workspace-root');
|
|
37
|
+
|
|
38
|
+
// src/utilities/helpers.ts
|
|
39
|
+
function handleSync(fn) {
|
|
40
|
+
try {
|
|
41
|
+
return fn();
|
|
42
|
+
} catch (error_) {
|
|
43
|
+
return error_;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
_chunkBGYQAVKQcjs.__name.call(void 0, handleSync, "handleSync");
|
|
47
|
+
async function handleAsync(fn) {
|
|
48
|
+
try {
|
|
49
|
+
return await fn();
|
|
50
|
+
} catch (error_) {
|
|
51
|
+
return error_;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
_chunkBGYQAVKQcjs.__name.call(void 0, handleAsync, "handleAsync");
|
|
55
|
+
var handle = handleSync;
|
|
56
|
+
handle.async = handleAsync;
|
|
57
|
+
var skip = Symbol("skip");
|
|
58
|
+
function transduceSync(list, transformer) {
|
|
59
|
+
const transduced = [];
|
|
60
|
+
for (const [i, element_] of list.entries()) {
|
|
61
|
+
const transformed = transformer(element_, i);
|
|
62
|
+
if (transformed !== skip) {
|
|
63
|
+
transduced[transduced.length] = transformed;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return transduced;
|
|
67
|
+
}
|
|
68
|
+
_chunkBGYQAVKQcjs.__name.call(void 0, transduceSync, "transduceSync");
|
|
69
|
+
async function transduceAsync(list, transformer) {
|
|
70
|
+
const transduced = [];
|
|
71
|
+
await Promise.all(list.entries().map(async ([i, element_]) => {
|
|
72
|
+
const transformed = await transformer(element_, i);
|
|
73
|
+
if (transformed !== skip) {
|
|
74
|
+
transduced[transduced.length] = transformed;
|
|
75
|
+
}
|
|
76
|
+
}));
|
|
77
|
+
return transduced;
|
|
78
|
+
}
|
|
79
|
+
_chunkBGYQAVKQcjs.__name.call(void 0, transduceAsync, "transduceAsync");
|
|
80
|
+
var Filter = /* @__PURE__ */ _chunkBGYQAVKQcjs.__name.call(void 0, (filter) => (item) => {
|
|
81
|
+
return filter(item) ? item : skip;
|
|
82
|
+
}, "Filter");
|
|
83
|
+
var Mapper = /* @__PURE__ */ _chunkBGYQAVKQcjs.__name.call(void 0, (mapper) => (item) => {
|
|
84
|
+
return mapper(item);
|
|
85
|
+
}, "Mapper");
|
|
86
|
+
var transduce = transduceSync;
|
|
87
|
+
transduce.async = transduceAsync;
|
|
88
|
+
function pipeSync(fn, ...fns) {
|
|
89
|
+
return (...args) => {
|
|
90
|
+
let result = fn(...args);
|
|
91
|
+
for (let i = 0; result !== skip && i < fns.length; ++i) {
|
|
92
|
+
result = _optionalChain([fns, 'access', _ => _[i], 'optionalCall', _2 => _2(result)]);
|
|
93
|
+
}
|
|
94
|
+
return result;
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
_chunkBGYQAVKQcjs.__name.call(void 0, pipeSync, "pipeSync");
|
|
98
|
+
function pipeAsync(fn, ...fns) {
|
|
99
|
+
return async (...args) => {
|
|
100
|
+
let result = await fn(...args);
|
|
101
|
+
for (let i = 0; result !== skip && i < fns.length; ++i) {
|
|
102
|
+
result = await _optionalChain([fns, 'access', _3 => _3[i], 'optionalCall', _4 => _4(result)]);
|
|
103
|
+
}
|
|
104
|
+
return result;
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
_chunkBGYQAVKQcjs.__name.call(void 0, pipeAsync, "pipeAsync");
|
|
108
|
+
var pipe = pipeSync;
|
|
109
|
+
pipe.async = pipeAsync;
|
|
110
|
+
|
|
111
|
+
// src/build.ts
|
|
112
|
+
var resolveOptions = /* @__PURE__ */ _chunkBGYQAVKQcjs.__name.call(void 0, async (options) => {
|
|
113
|
+
const projectRoot = options.projectRoot;
|
|
114
|
+
const workspaceRoot = _findworkspaceroot.findWorkspaceRoot.call(void 0, projectRoot);
|
|
115
|
+
if (!workspaceRoot) {
|
|
116
|
+
throw new Error("Cannot find Nx workspace root");
|
|
117
|
+
}
|
|
118
|
+
const nxJsonPath = _devkit.joinPathFragments.call(void 0, workspaceRoot.dir, "nx.json");
|
|
119
|
+
if (!await _node.hfs.isFile(nxJsonPath)) {
|
|
120
|
+
throw new Error("Cannot find Nx workspace configuration");
|
|
121
|
+
}
|
|
122
|
+
const projectGraph = await _devkit.createProjectGraphAsync.call(void 0, {
|
|
123
|
+
exitOnError: true
|
|
124
|
+
});
|
|
125
|
+
const projectJsonPath = _devkit.joinPathFragments.call(void 0, workspaceRoot.dir, projectRoot, "project.json");
|
|
126
|
+
if (!await _node.hfs.isFile(projectJsonPath)) {
|
|
127
|
+
throw new Error("Cannot find project.json configuration");
|
|
128
|
+
}
|
|
129
|
+
const projectJson = await _node.hfs.json(projectJsonPath);
|
|
130
|
+
const projectName = projectJson.name;
|
|
131
|
+
const projectConfigurations = _devkit.readProjectsConfigurationFromProjectGraph.call(void 0, projectGraph);
|
|
132
|
+
if (!_optionalChain([projectConfigurations, 'optionalAccess', _5 => _5.projects, 'optionalAccess', _6 => _6[projectName]])) {
|
|
133
|
+
throw new Error("The Build process failed because the project does not have a valid configuration in the project.json file. Check if the file exists in the root of the project.");
|
|
134
|
+
}
|
|
135
|
+
return {
|
|
136
|
+
..._chunkNVGEXPTGcjs.DEFAULT_BUILD_OPTIONS,
|
|
137
|
+
format: "cjs",
|
|
138
|
+
outExtension: {
|
|
139
|
+
".js": ".js"
|
|
140
|
+
},
|
|
141
|
+
resolveExtensions: [
|
|
142
|
+
".ts",
|
|
143
|
+
".js",
|
|
144
|
+
".node"
|
|
145
|
+
],
|
|
146
|
+
entryPoints: _globby.globbySync.call(void 0, "./src/**/*.{j,t}s", {
|
|
147
|
+
ignore: [
|
|
148
|
+
"./src/__tests__/**/*"
|
|
149
|
+
]
|
|
150
|
+
}),
|
|
151
|
+
mainFields: [
|
|
152
|
+
"module",
|
|
153
|
+
"main"
|
|
154
|
+
],
|
|
155
|
+
...options,
|
|
156
|
+
outdir: options.outdir || _devkit.joinPathFragments.call(void 0, workspaceRoot.dir, "dist", projectRoot),
|
|
157
|
+
plugins: [
|
|
158
|
+
..._nullishCoalesce(options.plugins, () => ( [])),
|
|
159
|
+
_chunkWLHWKRZBcjs.resolvePathsPlugin,
|
|
160
|
+
_chunk3C3PXJUMcjs.fixImportsPlugin,
|
|
161
|
+
_chunkA6CGWMV7cjs.tscPlugin.call(void 0, options.emitTypes),
|
|
162
|
+
_chunkDCWECOOScjs.onErrorPlugin
|
|
163
|
+
],
|
|
164
|
+
external: [
|
|
165
|
+
..._nullishCoalesce(options.external, () => ( []))
|
|
166
|
+
],
|
|
167
|
+
name: `${options.name || projectName}-${options.format || "cjs"}`,
|
|
168
|
+
projectConfigurations,
|
|
169
|
+
projectName,
|
|
170
|
+
projectGraph,
|
|
171
|
+
workspaceRoot
|
|
172
|
+
};
|
|
173
|
+
}, "resolveOptions");
|
|
174
|
+
var generatePackageJson = /* @__PURE__ */ _chunkBGYQAVKQcjs.__name.call(void 0, async (options) => {
|
|
175
|
+
const nxJsonPath = _devkit.joinPathFragments.call(void 0, options.workspaceRoot.dir, "nx.json");
|
|
176
|
+
if (!await _node.hfs.isFile(nxJsonPath)) {
|
|
177
|
+
throw new Error("Cannot find Nx workspace configuration");
|
|
178
|
+
}
|
|
179
|
+
const projectJsonPath = _devkit.joinPathFragments.call(void 0, options.workspaceRoot.dir, options.projectRoot, "project.json");
|
|
180
|
+
if (!await _node.hfs.isFile(projectJsonPath)) {
|
|
181
|
+
throw new Error("Cannot find project.json configuration");
|
|
182
|
+
}
|
|
183
|
+
if (!_optionalChain([options, 'access', _7 => _7.projectConfigurations, 'optionalAccess', _8 => _8.projects, 'optionalAccess', _9 => _9[options.projectName]])) {
|
|
184
|
+
throw new Error("The Build process failed because the project does not have a valid configuration in the project.json file. Check if the file exists in the root of the project.");
|
|
185
|
+
}
|
|
186
|
+
const packageJsonPath = _devkit.joinPathFragments.call(void 0, options.projectRoot, "project.json");
|
|
187
|
+
if (!await _node.hfs.isFile(packageJsonPath)) {
|
|
188
|
+
throw new Error("Cannot find package.json configuration");
|
|
189
|
+
}
|
|
190
|
+
const packageJson = await _node.hfs.json(_devkit.joinPathFragments.call(void 0, options.workspaceRoot.dir, options.projectRoot, "package.json"));
|
|
191
|
+
const projectDependencies = _buildablelibsutils.calculateProjectBuildableDependencies.call(void 0, void 0, options.projectGraph, options.workspaceRoot.dir, options.projectName, process.env.NX_TASK_TARGET_TARGET || "build", process.env.NX_TASK_TARGET_CONFIGURATION || "production", true);
|
|
192
|
+
const localPackages = projectDependencies.dependencies.filter((dep) => dep.node.type === "lib" && dep.node.data.root !== options.projectRoot && dep.node.data.root !== options.workspaceRoot.dir).reduce((ret, project) => {
|
|
193
|
+
const projectNode = project.node;
|
|
194
|
+
if (projectNode.data.root) {
|
|
195
|
+
const projectPackageJsonPath = _devkit.joinPathFragments.call(void 0, options.workspaceRoot.dir, projectNode.data.root, "package.json");
|
|
196
|
+
if (_fs.existsSync.call(void 0, projectPackageJsonPath)) {
|
|
197
|
+
const projectPackageJson = _devkit.readJsonFile.call(void 0, projectPackageJsonPath);
|
|
198
|
+
if (projectPackageJson.private !== false) {
|
|
199
|
+
ret.push(projectPackageJson);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
return ret;
|
|
204
|
+
}, []);
|
|
205
|
+
if (localPackages.length > 0) {
|
|
206
|
+
_chunkRJQ3LCGJcjs.writeLog.call(void 0, "trace", `\u{1F4E6} Adding local packages to package.json: ${localPackages.map((p) => p.name).join(", ")}`);
|
|
207
|
+
packageJson.peerDependencies = localPackages.reduce((ret, localPackage) => {
|
|
208
|
+
if (!ret[localPackage.name]) {
|
|
209
|
+
ret[localPackage.name] = `>=${localPackage.version || "0.0.1"}`;
|
|
210
|
+
}
|
|
211
|
+
return ret;
|
|
212
|
+
}, _nullishCoalesce(packageJson.peerDependencies, () => ( {})));
|
|
213
|
+
packageJson.peerDependenciesMeta = localPackages.reduce((ret, localPackage) => {
|
|
214
|
+
if (!ret[localPackage.name]) {
|
|
215
|
+
ret[localPackage.name] = {
|
|
216
|
+
optional: false
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
return ret;
|
|
220
|
+
}, _nullishCoalesce(packageJson.peerDependenciesMeta, () => ( {})));
|
|
221
|
+
packageJson.devDependencies = localPackages.reduce((ret, localPackage) => {
|
|
222
|
+
if (!ret[localPackage.name]) {
|
|
223
|
+
ret[localPackage.name] = localPackage.version || "0.0.1";
|
|
224
|
+
}
|
|
225
|
+
return ret;
|
|
226
|
+
}, _nullishCoalesce(packageJson.peerDependencies, () => ( {})));
|
|
227
|
+
} else {
|
|
228
|
+
_chunkRJQ3LCGJcjs.writeLog.call(void 0, "trace", "\u{1F4E6} No local packages dependencies to add to package.json");
|
|
229
|
+
}
|
|
230
|
+
packageJson.main = "./dist/index.cjs";
|
|
231
|
+
packageJson.module = "./dist/index.mjs";
|
|
232
|
+
packageJson.types = "./dist/index.d.ts";
|
|
233
|
+
await _devkit.writeJsonFile.call(void 0, _devkit.joinPathFragments.call(void 0, options.outdir, "package.json"), packageJson);
|
|
234
|
+
return options;
|
|
235
|
+
}, "generatePackageJson");
|
|
236
|
+
async function createOptions(options) {
|
|
237
|
+
return _estoolkit.flatten.call(void 0, await Promise.all(_compat.map.call(void 0, options, (options2) => [
|
|
238
|
+
// we defer it so that we don't trigger glob immediately
|
|
239
|
+
() => resolveOptions(options2)
|
|
240
|
+
])));
|
|
241
|
+
}
|
|
242
|
+
_chunkBGYQAVKQcjs.__name.call(void 0, createOptions, "createOptions");
|
|
243
|
+
async function computeOptions(options) {
|
|
244
|
+
return options();
|
|
245
|
+
}
|
|
246
|
+
_chunkBGYQAVKQcjs.__name.call(void 0, computeOptions, "computeOptions");
|
|
247
|
+
async function executeEsBuild(options) {
|
|
248
|
+
if (process.env.WATCH === "true") {
|
|
249
|
+
const context2 = await esbuild.context(_estoolkit.omit.call(void 0, options, [
|
|
250
|
+
"name",
|
|
251
|
+
"emitTypes",
|
|
252
|
+
"emitMetafile"
|
|
253
|
+
]));
|
|
254
|
+
watch(context2, options);
|
|
255
|
+
}
|
|
256
|
+
const build3 = await esbuild.build(_estoolkit.omit.call(void 0, options, [
|
|
257
|
+
"name",
|
|
258
|
+
"emitTypes",
|
|
259
|
+
"emitMetafile"
|
|
260
|
+
]));
|
|
261
|
+
if (build3.metafile && options.emitMetafile) {
|
|
262
|
+
const metafilePath = `${options.outdir}/${options.name}.meta.json`;
|
|
263
|
+
await _node.hfs.write(metafilePath, JSON.stringify(build3.metafile));
|
|
264
|
+
}
|
|
265
|
+
return [
|
|
266
|
+
options,
|
|
267
|
+
build3
|
|
268
|
+
];
|
|
269
|
+
}
|
|
270
|
+
_chunkBGYQAVKQcjs.__name.call(void 0, executeEsBuild, "executeEsBuild");
|
|
271
|
+
async function dependencyCheck(options) {
|
|
272
|
+
if (process.env.DEV === "true") return void 0;
|
|
273
|
+
if (process.env.CI && !process.env.BUILDKITE) return void 0;
|
|
274
|
+
const buildPromise = esbuild.build({
|
|
275
|
+
entryPoints: _globby.globbySync.call(void 0, "**/*.{j,t}s", {
|
|
276
|
+
// We don't check dependencies in ecosystem tests because tests are isolated from the build.
|
|
277
|
+
ignore: [
|
|
278
|
+
"./src/__tests__/**/*",
|
|
279
|
+
"./tests/e2e/**/*",
|
|
280
|
+
"./dist/**/*"
|
|
281
|
+
],
|
|
282
|
+
gitignore: true
|
|
283
|
+
}),
|
|
284
|
+
logLevel: "silent",
|
|
285
|
+
bundle: true,
|
|
286
|
+
write: false,
|
|
287
|
+
outdir: "out",
|
|
288
|
+
plugins: [
|
|
289
|
+
_chunkMTKAAECGcjs.depsCheckPlugin.call(void 0, options.bundle)
|
|
290
|
+
]
|
|
291
|
+
});
|
|
292
|
+
await buildPromise.catch(() => {
|
|
293
|
+
});
|
|
294
|
+
return void 0;
|
|
295
|
+
}
|
|
296
|
+
_chunkBGYQAVKQcjs.__name.call(void 0, dependencyCheck, "dependencyCheck");
|
|
297
|
+
async function build2(options) {
|
|
298
|
+
void transduce.async(options, dependencyCheck);
|
|
299
|
+
return transduce.async(await createOptions(options), pipe.async(computeOptions, generatePackageJson, executeEsBuild));
|
|
300
|
+
}
|
|
301
|
+
_chunkBGYQAVKQcjs.__name.call(void 0, build2, "build");
|
|
302
|
+
var watch = /* @__PURE__ */ _chunkBGYQAVKQcjs.__name.call(void 0, (context2, options) => {
|
|
303
|
+
if (process.env.WATCH !== "true") return context2;
|
|
304
|
+
const config = {
|
|
305
|
+
ignoreInitial: true,
|
|
306
|
+
useFsEvents: true,
|
|
307
|
+
ignored: [
|
|
308
|
+
"./src/__tests__/**/*",
|
|
309
|
+
"./package.json"
|
|
310
|
+
]
|
|
311
|
+
};
|
|
312
|
+
const changeWatcher = _chokidar.watch.call(void 0, [
|
|
313
|
+
"./src/**/*"
|
|
314
|
+
], config);
|
|
315
|
+
const fastRebuild = _estoolkit.debounce.call(void 0, async () => {
|
|
316
|
+
const timeBefore = Date.now();
|
|
317
|
+
const rebuildResult = await handle.async(() => {
|
|
318
|
+
return context2.rebuild();
|
|
319
|
+
});
|
|
320
|
+
if (rebuildResult instanceof Error) {
|
|
321
|
+
_chunkRJQ3LCGJcjs.writeLog.call(void 0, "error", rebuildResult.message);
|
|
322
|
+
}
|
|
323
|
+
_chunkRJQ3LCGJcjs.writeLog.call(void 0, "log", `${Date.now() - timeBefore}ms [${_nullishCoalesce(options.name, () => ( ""))}]`);
|
|
324
|
+
}, 10);
|
|
325
|
+
changeWatcher.on("change", fastRebuild);
|
|
326
|
+
return void 0;
|
|
327
|
+
}, "watch");
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
exports.handle = handle; exports.skip = skip; exports.Filter = Filter; exports.Mapper = Mapper; exports.transduce = transduce; exports.pipe = pipe; exports.build = build2;
|