@bemedev/dev-utils 1.0.1 → 1.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 +59 -11
- package/lib/build-tests/addTarball.d.ts +1 -1
- package/lib/build-tests/buildPackageJson.d.ts +3 -3
- package/lib/build-tests/cleanup.d.ts +1 -1
- package/lib/build-tests/cli/cli.d.ts +51 -1
- package/lib/build-tests/cli/index.d.ts +1 -0
- package/lib/build-tests/cli/post.d.ts +5 -1
- package/lib/build-tests/cli/pre.d.ts +5 -1
- package/lib/build-tests/cli/test.d.ts +15 -1
- package/lib/build-tests/constants.d.ts +1 -1
- package/lib/build-tests/getRelativePath.d.ts +1 -1
- package/lib/build-tests/getTypescriptOutdir.d.ts +1 -1
- package/lib/build-tests/import.d.ts +2 -2
- package/lib/build-tests/imports/create.d.ts +3 -3
- package/lib/build-tests/imports/helper.cjs.map +1 -1
- package/lib/build-tests/imports/helper.d.ts +7 -3
- package/lib/build-tests/imports/helper.js.map +1 -1
- package/lib/build-tests/imports/index.d.ts +1 -1
- package/lib/build-tests/index.d.ts +5 -5
- package/lib/build-tests/pack.d.ts +1 -1
- package/lib/rolldown-config/config.cjs +23 -2
- package/lib/rolldown-config/config.cjs.map +1 -1
- package/lib/rolldown-config/config.d.ts +1 -1
- package/lib/rolldown-config/config.js +23 -2
- package/lib/rolldown-config/config.js.map +1 -1
- package/lib/rolldown-config/constants.d.ts +5 -5
- package/lib/rolldown-config/helpers.d.ts +2 -2
- package/lib/rolldown-config/index.d.ts +3 -3
- package/lib/rolldown-config/input.d.ts +1 -1
- package/lib/rolldown-config/output.cjs +4 -2
- package/lib/rolldown-config/output.cjs.map +1 -1
- package/lib/rolldown-config/output.d.ts +15 -1
- package/lib/rolldown-config/output.js +4 -2
- package/lib/rolldown-config/output.js.map +1 -1
- package/lib/rolldown-config/plugins/circulars.d.ts +9 -9
- package/lib/rolldown-config/plugins/clean.cjs +4 -2
- package/lib/rolldown-config/plugins/clean.cjs.map +1 -1
- package/lib/rolldown-config/plugins/clean.d.ts +13 -4
- package/lib/rolldown-config/plugins/clean.js +4 -2
- package/lib/rolldown-config/plugins/clean.js.map +1 -1
- package/lib/rolldown-config/plugins/externals.d.ts +7 -7
- package/lib/rolldown-config/plugins/index.cjs +8 -8
- package/lib/rolldown-config/plugins/index.cjs.map +1 -1
- package/lib/rolldown-config/plugins/index.d.ts +31 -2
- package/lib/rolldown-config/plugins/index.js +6 -7
- package/lib/rolldown-config/plugins/index.js.map +1 -1
- package/lib/rolldown-config/plugins/typescript.cjs +29 -41
- package/lib/rolldown-config/plugins/typescript.cjs.map +1 -1
- package/lib/rolldown-config/plugins/typescript.config.cjs +51 -39
- package/lib/rolldown-config/plugins/typescript.config.cjs.map +1 -1
- package/lib/rolldown-config/plugins/typescript.config.d.ts +3 -4
- package/lib/rolldown-config/plugins/typescript.config.js +51 -41
- package/lib/rolldown-config/plugins/typescript.config.js.map +1 -1
- package/lib/rolldown-config/plugins/typescript.d.ts +6 -6
- package/lib/rolldown-config/plugins/typescript.fast.cjs +80 -0
- package/lib/rolldown-config/plugins/typescript.fast.cjs.map +1 -0
- package/lib/rolldown-config/plugins/typescript.fast.d.ts +9 -0
- package/lib/rolldown-config/plugins/typescript.fast.js +77 -0
- package/lib/rolldown-config/plugins/typescript.fast.js.map +1 -0
- package/lib/rolldown-config/plugins/typescript.js +29 -43
- package/lib/rolldown-config/plugins/typescript.js.map +1 -1
- package/lib/rolldown-config/types.d.ts +14 -13
- package/lib/utils/array.d.ts +1 -1
- package/lib/utils/bemedev/globals/types.d.ts +4 -0
- package/lib/{vitest-extended → utils}/bemedev/globals/utils/_unknown.cjs +1 -1
- package/lib/utils/bemedev/globals/utils/_unknown.cjs.map +1 -0
- package/lib/utils/bemedev/globals/utils/_unknown.d.ts +12 -0
- package/lib/{vitest-extended → utils}/bemedev/globals/utils/_unknown.js +1 -1
- package/lib/utils/bemedev/globals/utils/_unknown.js.map +1 -0
- package/lib/utils/bemedev/globals/utils/expandFn.cjs +11 -0
- package/lib/utils/bemedev/globals/utils/expandFn.cjs.map +1 -0
- package/lib/utils/bemedev/globals/utils/expandFn.d.ts +2 -0
- package/lib/utils/bemedev/globals/utils/expandFn.js +10 -0
- package/lib/utils/bemedev/globals/utils/expandFn.js.map +1 -0
- package/lib/utils/identity.d.ts +1 -1
- package/lib/utils/index.cjs +2 -0
- package/lib/utils/index.d.ts +5 -4
- package/lib/utils/index.js +2 -1
- package/lib/utils/sleep.d.ts +1 -1
- package/lib/utils/types.d.ts +1 -4
- package/lib/vitest-exclude/index.d.ts +1 -1
- package/lib/vitest-exclude/types.d.ts +11 -8
- package/lib/vitest-exclude/vitest.cjs +0 -2
- package/lib/vitest-exclude/vitest.cjs.map +1 -1
- package/lib/vitest-exclude/vitest.d.ts +27 -15
- package/lib/vitest-exclude/vitest.js +0 -2
- package/lib/vitest-exclude/vitest.js.map +1 -1
- package/lib/vitest-exclude/vitest.utils.d.ts +2 -2
- package/lib/vitest-extended/acceptation.cjs.map +1 -1
- package/lib/vitest-extended/acceptation.d.ts +3 -2
- package/lib/vitest-extended/acceptation.js.map +1 -1
- package/lib/vitest-extended/createTests.cjs.map +1 -1
- package/lib/vitest-extended/createTests.d.ts +55 -34
- package/lib/vitest-extended/createTests.js.map +1 -1
- package/lib/vitest-extended/createTests.types.d.ts +6 -10
- package/lib/vitest-extended/done.d.ts +14 -8
- package/lib/vitest-extended/each/error.d.ts +1 -1
- package/lib/vitest-extended/each/error.types.d.ts +4 -10
- package/lib/vitest-extended/each/index.d.ts +2 -2
- package/lib/vitest-extended/each/pass.d.ts +26 -26
- package/lib/vitest-extended/each/pass.types.d.ts +6 -18
- package/lib/vitest-extended/fakeWaiter.d.ts +3 -3
- package/lib/vitest-extended/identity.d.ts +2 -2
- package/lib/vitest-extended/index.cjs +2 -0
- package/lib/vitest-extended/index.d.ts +7 -6
- package/lib/vitest-extended/index.js +2 -1
- package/lib/vitest-extended/isDefined.cjs.map +1 -1
- package/lib/vitest-extended/isDefined.d.ts +1 -1
- package/lib/vitest-extended/isDefined.js.map +1 -1
- package/lib/vitest-extended/isFunction.d.ts +1 -1
- package/lib/vitest-extended/project.cjs +23 -0
- package/lib/vitest-extended/project.cjs.map +1 -0
- package/lib/vitest-extended/project.d.ts +2 -0
- package/lib/vitest-extended/project.js +22 -0
- package/lib/vitest-extended/project.js.map +1 -0
- package/lib/vitest-extended/toArray.d.ts +1 -1
- package/lib/vitest-extended/toStringFlat.cjs.map +1 -1
- package/lib/vitest-extended/toStringFlat.d.ts +1 -1
- package/lib/vitest-extended/toStringFlat.js.map +1 -1
- package/lib/vitest-extended/types.d.ts +38 -40
- package/package.json +4 -8
- package/lib/vitest-extended/bemedev/globals/types.d.ts +0 -6
- package/lib/vitest-extended/bemedev/globals/utils/_unknown.cjs.map +0 -1
- package/lib/vitest-extended/bemedev/globals/utils/_unknown.d.ts +0 -12
- package/lib/vitest-extended/bemedev/globals/utils/_unknown.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clean.cjs","names":["toArray","withoutExtension","WARNING_CODES","readTsConfig","
|
|
1
|
+
{"version":3,"file":"clean.cjs","names":["toArray","withoutExtension","WARNING_CODES","readTsConfig","existsSync"],"sources":["../../../src/rolldown-config/plugins/clean.ts"],"sourcesContent":["import { existsSync } from 'fs';\nimport { relative } from 'node:path';\n\nimport { findConfigFile } from '@typescript/typescript6';\nimport { globSync } from 'glob';\nimport type { RolldownPluginOption } from 'rolldown';\n\nimport { toArray } from '#utils';\n\nimport { DEFAULT_DIR, WARNING_CODES } from '../constants';\nimport { cleanupJS, withoutExtension } from '../helpers';\nimport { readTsConfig } from './typescript.config';\n\nexport type EndPluginOptions = {\n ignoresJS?: string | string[];\n sourcemap?: boolean;\n dir?: string;\n};\n\nexport const clean = (options: EndPluginOptions) => {\n const { ignoresJS, sourcemap = false, dir } = options;\n\n const _ignoresJS = toArray(ignoresJS);\n\n const out = {\n name: 'end-bemedev',\n\n onLog: {\n handler: (_, { code, names }) => {\n const EMPTY_CHUNKS = _ignoresJS\n .map(f => globSync(f, { nodir: true }))\n .flat()\n .map(withoutExtension)\n .map(file => relative('src', file));\n\n const check =\n code === WARNING_CODES.EMPTY_BUNDLE &&\n names?.every(name => EMPTY_CHUNKS.includes(name));\n\n if (check) {\n const STARS = '*'.repeat(20);\n console.log(STARS);\n console.log('[end-bemedev] Skipping empty chunk warnings for:');\n names?.forEach(name => console.log(` -> 📄 ${name}`));\n console.log(STARS);\n return false;\n }\n\n return;\n },\n },\n\n closeBundle: {\n order: 'post',\n handler: () => {\n const cwd = process.cwd();\n\n const tsconfigPath = findConfigFile(\n cwd,\n existsSync,\n 'tsconfig.json',\n )!;\n const _outDir = readTsConfig(tsconfigPath).options.outDir;\n const outDir = _outDir ?? dir ?? DEFAULT_DIR;\n if (_ignoresJS.length > 0) {\n try {\n const files = new Set<string>();\n _ignoresJS.forEach(pat => {\n const globs = globSync(pat, { nodir: true });\n globs.forEach(file => files.add(file));\n });\n cleanupJS(files, outDir, sourcemap);\n console.log('Build finished');\n /* v8 ignore next 3 */\n } catch (err) {\n console.error('[end-bemedev] cleanup failed:', err);\n }\n }\n },\n },\n } satisfies RolldownPluginOption;\n\n return out;\n};\n"],"mappings":";;;;;;;;;;AAmBA,MAAa,SAAS,YAA8B;CAClD,MAAM,EAAE,WAAW,YAAY,OAAO,QAAQ;CAE9C,MAAM,aAAaA,oBAAAA,QAAQ,SAAS;CA4DpC,OAAO;EAzDL,MAAM;EAEN,OAAO,EACL,UAAU,GAAG,EAAE,MAAM,YAAY;GAC/B,MAAM,eAAe,WAClB,KAAI,OAAA,GAAA,KAAA,SAAA,CAAc,GAAG,EAAE,OAAO,KAAK,CAAC,CAAC,CAAC,CACtC,KAAK,CAAC,CACN,IAAIC,gCAAAA,gBAAgB,CAAC,CACrB,KAAI,UAAA,GAAA,KAAA,SAAA,CAAiB,OAAO,IAAI,CAAC;GAMpC,IAHE,SAASC,kCAAAA,cAAc,gBACvB,OAAO,OAAM,SAAQ,aAAa,SAAS,IAAI,CAAC,GAEvC;IACT,MAAM,QAAQ,IAAI,OAAO,EAAE;IAC3B,QAAQ,IAAI,KAAK;IACjB,QAAQ,IAAI,kDAAkD;IAC9D,OAAO,SAAQ,SAAQ,QAAQ,IAAI,WAAW,MAAM,CAAC;IACrD,QAAQ,IAAI,KAAK;IACjB,OAAO;GACT;EAGF,EACF;EAEA,aAAa;GACX,OAAO;GACP,eAAe;IASb,MAAM,SADUC,kDAAAA,cAAAA,GAAAA,wBAAAA,eAAAA,CAPJ,QAAQ,IAGhB,GACFC,GAAAA,YACA,eAEsC,CAAC,CAAC,CAAC,QAAQ,UACzB,OAAA;IAC1B,IAAI,WAAW,SAAS,GACtB,IAAI;KACF,MAAM,wBAAQ,IAAI,IAAY;KAC9B,WAAW,SAAQ,QAAO;MAExB,CAAA,GAAA,KAAA,SAAA,CADuB,KAAK,EAAE,OAAO,KAAK,CACtC,CAAC,CAAC,SAAQ,SAAQ,MAAM,IAAI,IAAI,CAAC;KACvC,CAAC;KACD,gCAAA,UAAU,OAAO,QAAQ,SAAS;KAClC,QAAQ,IAAI,gBAAgB;IAE9B,SAAS,KAAK;KACZ,QAAQ,MAAM,iCAAiC,GAAG;IACpD;GAEJ;EACF;CAGO;AACX"}
|
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
export type EndPluginOptions = {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
ignoresJS?: string | string[];
|
|
3
|
+
sourcemap?: boolean;
|
|
4
|
+
dir?: string;
|
|
5
|
+
};
|
|
6
|
+
export declare const clean: (options: EndPluginOptions) => {
|
|
7
|
+
name: string;
|
|
8
|
+
onLog: {
|
|
9
|
+
handler: (this: import("rolldown").MinimalPluginContext, _: import("rolldown").LogLevel, { code, names }: import("rolldown").RolldownLog) => false | undefined;
|
|
10
|
+
};
|
|
11
|
+
closeBundle: {
|
|
12
|
+
order: "post";
|
|
13
|
+
handler: () => void;
|
|
14
|
+
};
|
|
5
15
|
};
|
|
6
|
-
export declare const clean: unknown;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { toArray } from "../../utils/array.js";
|
|
2
2
|
import { WARNING_CODES } from "../constants.js";
|
|
3
|
+
import { readTsConfig } from "./typescript.config.js";
|
|
3
4
|
import { cleanupJS, withoutExtension } from "../helpers.js";
|
|
4
|
-
import {
|
|
5
|
+
import { existsSync } from "fs";
|
|
5
6
|
import { relative } from "path";
|
|
6
7
|
import { globSync } from "glob";
|
|
8
|
+
import { findConfigFile } from "@typescript/typescript6";
|
|
7
9
|
//#region src/rolldown-config/plugins/clean.ts
|
|
8
10
|
const clean = (options) => {
|
|
9
11
|
const { ignoresJS, sourcemap = false, dir } = options;
|
|
@@ -24,7 +26,7 @@ const clean = (options) => {
|
|
|
24
26
|
closeBundle: {
|
|
25
27
|
order: "post",
|
|
26
28
|
handler: () => {
|
|
27
|
-
const outDir = readTsConfig(findConfigFile(process.cwd(), "tsconfig.json")).
|
|
29
|
+
const outDir = readTsConfig(findConfigFile(process.cwd(), existsSync, "tsconfig.json")).options.outDir ?? dir ?? "lib";
|
|
28
30
|
if (_ignoresJS.length > 0) try {
|
|
29
31
|
const files = /* @__PURE__ */ new Set();
|
|
30
32
|
_ignoresJS.forEach((pat) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clean.js","names":[],"sources":["../../../src/rolldown-config/plugins/clean.ts"],"sourcesContent":["import { relative } from 'node:path';\n\nimport { globSync } from 'glob';\nimport type { RolldownPluginOption } from 'rolldown';\n\nimport { toArray } from '#utils';\n\nimport { DEFAULT_DIR, WARNING_CODES } from '../constants';\nimport { cleanupJS, withoutExtension } from '../helpers';\nimport {
|
|
1
|
+
{"version":3,"file":"clean.js","names":[],"sources":["../../../src/rolldown-config/plugins/clean.ts"],"sourcesContent":["import { existsSync } from 'fs';\nimport { relative } from 'node:path';\n\nimport { findConfigFile } from '@typescript/typescript6';\nimport { globSync } from 'glob';\nimport type { RolldownPluginOption } from 'rolldown';\n\nimport { toArray } from '#utils';\n\nimport { DEFAULT_DIR, WARNING_CODES } from '../constants';\nimport { cleanupJS, withoutExtension } from '../helpers';\nimport { readTsConfig } from './typescript.config';\n\nexport type EndPluginOptions = {\n ignoresJS?: string | string[];\n sourcemap?: boolean;\n dir?: string;\n};\n\nexport const clean = (options: EndPluginOptions) => {\n const { ignoresJS, sourcemap = false, dir } = options;\n\n const _ignoresJS = toArray(ignoresJS);\n\n const out = {\n name: 'end-bemedev',\n\n onLog: {\n handler: (_, { code, names }) => {\n const EMPTY_CHUNKS = _ignoresJS\n .map(f => globSync(f, { nodir: true }))\n .flat()\n .map(withoutExtension)\n .map(file => relative('src', file));\n\n const check =\n code === WARNING_CODES.EMPTY_BUNDLE &&\n names?.every(name => EMPTY_CHUNKS.includes(name));\n\n if (check) {\n const STARS = '*'.repeat(20);\n console.log(STARS);\n console.log('[end-bemedev] Skipping empty chunk warnings for:');\n names?.forEach(name => console.log(` -> 📄 ${name}`));\n console.log(STARS);\n return false;\n }\n\n return;\n },\n },\n\n closeBundle: {\n order: 'post',\n handler: () => {\n const cwd = process.cwd();\n\n const tsconfigPath = findConfigFile(\n cwd,\n existsSync,\n 'tsconfig.json',\n )!;\n const _outDir = readTsConfig(tsconfigPath).options.outDir;\n const outDir = _outDir ?? dir ?? DEFAULT_DIR;\n if (_ignoresJS.length > 0) {\n try {\n const files = new Set<string>();\n _ignoresJS.forEach(pat => {\n const globs = globSync(pat, { nodir: true });\n globs.forEach(file => files.add(file));\n });\n cleanupJS(files, outDir, sourcemap);\n console.log('Build finished');\n /* v8 ignore next 3 */\n } catch (err) {\n console.error('[end-bemedev] cleanup failed:', err);\n }\n }\n },\n },\n } satisfies RolldownPluginOption;\n\n return out;\n};\n"],"mappings":";;;;;;;;;AAmBA,MAAa,SAAS,YAA8B;CAClD,MAAM,EAAE,WAAW,YAAY,OAAO,QAAQ;CAE9C,MAAM,aAAa,QAAQ,SAAS;CA4DpC,OAAO;EAzDL,MAAM;EAEN,OAAO,EACL,UAAU,GAAG,EAAE,MAAM,YAAY;GAC/B,MAAM,eAAe,WAClB,KAAI,MAAK,SAAS,GAAG,EAAE,OAAO,KAAK,CAAC,CAAC,CAAC,CACtC,KAAK,CAAC,CACN,IAAI,gBAAgB,CAAC,CACrB,KAAI,SAAQ,SAAS,OAAO,IAAI,CAAC;GAMpC,IAHE,SAAS,cAAc,gBACvB,OAAO,OAAM,SAAQ,aAAa,SAAS,IAAI,CAAC,GAEvC;IACT,MAAM,QAAQ,IAAI,OAAO,EAAE;IAC3B,QAAQ,IAAI,KAAK;IACjB,QAAQ,IAAI,kDAAkD;IAC9D,OAAO,SAAQ,SAAQ,QAAQ,IAAI,WAAW,MAAM,CAAC;IACrD,QAAQ,IAAI,KAAK;IACjB,OAAO;GACT;EAGF,EACF;EAEA,aAAa;GACX,OAAO;GACP,eAAe;IASb,MAAM,SADU,aALK,eAFT,QAAQ,IAGhB,GACF,YACA,eAEsC,CAAC,CAAC,CAAC,QAAQ,UACzB,OAAA;IAC1B,IAAI,WAAW,SAAS,GACtB,IAAI;KACF,MAAM,wBAAQ,IAAI,IAAY;KAC9B,WAAW,SAAQ,QAAO;MAExB,SADuB,KAAK,EAAE,OAAO,KAAK,CACtC,CAAC,CAAC,SAAQ,SAAQ,MAAM,IAAI,IAAI,CAAC;KACvC,CAAC;KACD,UAAU,OAAO,QAAQ,SAAS;KAClC,QAAQ,IAAI,gBAAgB;IAE9B,SAAS,KAAK;KACZ,QAAQ,MAAM,iCAAiC,GAAG;IACpD;GAEJ;EACF;CAGO;AACX"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type { RolldownPluginOption } from
|
|
2
|
-
import { nodeExternals } from
|
|
1
|
+
import type { RolldownPluginOption } from 'rolldown';
|
|
2
|
+
import { nodeExternals } from 'rollup-plugin-node-externals';
|
|
3
3
|
export type NodeExternalsOptions = Parameters<typeof nodeExternals>[0];
|
|
4
4
|
/**
|
|
5
|
-
* Creates a configured node externals plugin instance
|
|
6
|
-
*
|
|
7
|
-
* @param options - Configuration options for node externals
|
|
8
|
-
* @returns Rolldown plugin
|
|
9
|
-
*/
|
|
5
|
+
* Creates a configured node externals plugin instance
|
|
6
|
+
*
|
|
7
|
+
* @param options - Configuration options for node externals
|
|
8
|
+
* @returns Rolldown plugin
|
|
9
|
+
*/
|
|
10
10
|
export declare function externals(options?: NodeExternalsOptions): RolldownPluginOption;
|
|
@@ -2,19 +2,19 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
2
2
|
const require_rolldown_config_plugins_circulars = require("./circulars.cjs");
|
|
3
3
|
const require_rolldown_config_plugins_clean = require("./clean.cjs");
|
|
4
4
|
const require_rolldown_config_plugins_externals = require("./externals.cjs");
|
|
5
|
+
const require_rolldown_config_plugins_typescript = require("./typescript.cjs");
|
|
6
|
+
const require_rolldown_config_plugins_typescript_fast = require("./typescript.fast.cjs");
|
|
7
|
+
let rolldown_plugins = require("rolldown/plugins");
|
|
5
8
|
//#region src/rolldown-config/plugins/index.ts
|
|
6
9
|
const PLUGIN_BUILDERS = {
|
|
7
|
-
typescript:
|
|
10
|
+
typescript: require_rolldown_config_plugins_typescript.typescript,
|
|
8
11
|
circulars: require_rolldown_config_plugins_circulars.circulars,
|
|
9
12
|
externals: require_rolldown_config_plugins_externals.externals,
|
|
10
|
-
clean: require_rolldown_config_plugins_clean.clean
|
|
13
|
+
clean: require_rolldown_config_plugins_clean.clean,
|
|
14
|
+
fast: require_rolldown_config_plugins_typescript_fast.typescriptFast,
|
|
15
|
+
esm: rolldown_plugins.esmExternalRequirePlugin
|
|
11
16
|
};
|
|
12
|
-
const DEFAULT_PLUGINS_ORDER =
|
|
13
|
-
"typescript",
|
|
14
|
-
"circulars",
|
|
15
|
-
"externals",
|
|
16
|
-
"clean"
|
|
17
|
-
];
|
|
17
|
+
const DEFAULT_PLUGINS_ORDER = Object.keys(PLUGIN_BUILDERS);
|
|
18
18
|
//#endregion
|
|
19
19
|
exports.DEFAULT_PLUGINS_ORDER = DEFAULT_PLUGINS_ORDER;
|
|
20
20
|
exports.PLUGIN_BUILDERS = PLUGIN_BUILDERS;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":[],"sources":["../../../src/rolldown-config/plugins/index.ts"],"sourcesContent":["import { circulars } from './circulars';\nimport { clean } from './clean';\nimport { externals } from './externals';\nimport { typescript } from './typescript';\
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["typescriptFast","esmExternalRequirePlugin"],"sources":["../../../src/rolldown-config/plugins/index.ts"],"sourcesContent":["import { esmExternalRequirePlugin } from 'rolldown/plugins';\n\nimport { circulars } from './circulars';\nimport { clean } from './clean';\nimport { externals } from './externals';\nimport { typescript } from './typescript';\nimport { typescriptFast } from './typescript.fast';\n\nexport const PLUGIN_BUILDERS = {\n typescript,\n circulars,\n externals,\n clean,\n fast: typescriptFast,\n esm: esmExternalRequirePlugin,\n};\n\nexport const DEFAULT_PLUGINS_ORDER = Object.keys(\n PLUGIN_BUILDERS,\n) as (keyof typeof PLUGIN_BUILDERS)[];\n"],"mappings":";;;;;;;;AAQA,MAAa,kBAAkB;CAC7B,YAAA,2CAAA;CACA,WAAA,0CAAA;CACA,WAAA,0CAAA;CACA,OAAA,sCAAA;CACA,MAAMA,gDAAAA;CACN,KAAKC,iBAAAA;AACP;AAEA,MAAa,wBAAwB,OAAO,KAC1C,eACF"}
|
|
@@ -1,2 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { esmExternalRequirePlugin } from 'rolldown/plugins';
|
|
2
|
+
import { circulars } from './circulars';
|
|
3
|
+
import { externals } from './externals';
|
|
4
|
+
export declare const PLUGIN_BUILDERS: {
|
|
5
|
+
typescript: ({ exclude, include, declarationMap, dir, }?: {
|
|
6
|
+
exclude?: string | string[];
|
|
7
|
+
include?: Record<string, string>;
|
|
8
|
+
declarationMap?: boolean;
|
|
9
|
+
dir?: string;
|
|
10
|
+
}) => import("rolldown").RolldownPluginOption;
|
|
11
|
+
circulars: typeof circulars;
|
|
12
|
+
externals: typeof externals;
|
|
13
|
+
clean: (options: import("./clean").EndPluginOptions) => {
|
|
14
|
+
name: string;
|
|
15
|
+
onLog: {
|
|
16
|
+
handler: (this: import("rolldown").MinimalPluginContext, _: import("rolldown").LogLevel, { code, names }: import("rolldown").RolldownLog) => false | undefined;
|
|
17
|
+
};
|
|
18
|
+
closeBundle: {
|
|
19
|
+
order: "post";
|
|
20
|
+
handler: () => void;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
fast: ({ exclude, include, declarationMap, dir, }?: {
|
|
24
|
+
exclude?: string | string[];
|
|
25
|
+
include?: Record<string, string>;
|
|
26
|
+
declarationMap?: boolean;
|
|
27
|
+
dir?: string;
|
|
28
|
+
}) => import("rolldown").RolldownPluginOption;
|
|
29
|
+
esm: typeof esmExternalRequirePlugin;
|
|
30
|
+
};
|
|
31
|
+
export declare const DEFAULT_PLUGINS_ORDER: (keyof typeof PLUGIN_BUILDERS)[];
|
|
@@ -2,19 +2,18 @@ import { circulars } from "./circulars.js";
|
|
|
2
2
|
import { clean } from "./clean.js";
|
|
3
3
|
import { externals } from "./externals.js";
|
|
4
4
|
import { typescript } from "./typescript.js";
|
|
5
|
+
import { typescriptFast } from "./typescript.fast.js";
|
|
6
|
+
import { esmExternalRequirePlugin } from "rolldown/plugins";
|
|
5
7
|
//#region src/rolldown-config/plugins/index.ts
|
|
6
8
|
const PLUGIN_BUILDERS = {
|
|
7
9
|
typescript,
|
|
8
10
|
circulars,
|
|
9
11
|
externals,
|
|
10
|
-
clean
|
|
12
|
+
clean,
|
|
13
|
+
fast: typescriptFast,
|
|
14
|
+
esm: esmExternalRequirePlugin
|
|
11
15
|
};
|
|
12
|
-
const DEFAULT_PLUGINS_ORDER =
|
|
13
|
-
"typescript",
|
|
14
|
-
"circulars",
|
|
15
|
-
"externals",
|
|
16
|
-
"clean"
|
|
17
|
-
];
|
|
16
|
+
const DEFAULT_PLUGINS_ORDER = Object.keys(PLUGIN_BUILDERS);
|
|
18
17
|
//#endregion
|
|
19
18
|
export { DEFAULT_PLUGINS_ORDER, PLUGIN_BUILDERS };
|
|
20
19
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../src/rolldown-config/plugins/index.ts"],"sourcesContent":["import { circulars } from './circulars';\nimport { clean } from './clean';\nimport { externals } from './externals';\nimport { typescript } from './typescript';\
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../src/rolldown-config/plugins/index.ts"],"sourcesContent":["import { esmExternalRequirePlugin } from 'rolldown/plugins';\n\nimport { circulars } from './circulars';\nimport { clean } from './clean';\nimport { externals } from './externals';\nimport { typescript } from './typescript';\nimport { typescriptFast } from './typescript.fast';\n\nexport const PLUGIN_BUILDERS = {\n typescript,\n circulars,\n externals,\n clean,\n fast: typescriptFast,\n esm: esmExternalRequirePlugin,\n};\n\nexport const DEFAULT_PLUGINS_ORDER = Object.keys(\n PLUGIN_BUILDERS,\n) as (keyof typeof PLUGIN_BUILDERS)[];\n"],"mappings":";;;;;;;AAQA,MAAa,kBAAkB;CAC7B;CACA;CACA;CACA;CACA,MAAM;CACN,KAAK;AACP;AAEA,MAAa,wBAAwB,OAAO,KAC1C,eACF"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_runtime = require("../../_virtual/_rolldown/runtime.cjs");
|
|
2
3
|
const require_utils_array = require("../../utils/array.cjs");
|
|
3
4
|
require("../constants.cjs");
|
|
4
5
|
const require_rolldown_config_plugins_typescript_config = require("./typescript.config.cjs");
|
|
5
6
|
let fs = require("fs");
|
|
6
|
-
let
|
|
7
|
-
|
|
8
|
-
let oxc_transform = require("oxc-transform");
|
|
7
|
+
let _typescript_typescript6 = require("@typescript/typescript6");
|
|
8
|
+
_typescript_typescript6 = require_runtime.__toESM(_typescript_typescript6, 1);
|
|
9
9
|
let tsc_alias = require("tsc-alias");
|
|
10
10
|
//#region src/rolldown-config/plugins/typescript.ts
|
|
11
11
|
const typescript = ({ exclude, include, declarationMap, dir } = {}) => {
|
|
@@ -21,46 +21,34 @@ const typescript = ({ exclude, include, declarationMap, dir } = {}) => {
|
|
|
21
21
|
async handler() {
|
|
22
22
|
if (done) return;
|
|
23
23
|
const cwd = process.cwd();
|
|
24
|
-
const tsconfigPath =
|
|
24
|
+
const tsconfigPath = _typescript_typescript6.default.findConfigFile(cwd, fs.existsSync, "tsconfig.json");
|
|
25
25
|
const configFile = require_rolldown_config_plugins_typescript_config.readTsConfig(tsconfigPath);
|
|
26
|
-
const
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
const relativePath = (0, path.relative)(rootDir, file);
|
|
40
|
-
let dtsName = relativePath;
|
|
41
|
-
if (relativePath.endsWith(".tsx")) dtsName = relativePath.slice(0, -4) + ".d.ts";
|
|
42
|
-
else if (relativePath.endsWith(".ts")) dtsName = relativePath.slice(0, -3) + ".d.ts";
|
|
43
|
-
else if (relativePath.endsWith(".cts")) dtsName = relativePath.slice(0, -4) + ".d.cts";
|
|
44
|
-
else if (relativePath.endsWith(".mts")) dtsName = relativePath.slice(0, -4) + ".d.mts";
|
|
45
|
-
const outPath = (0, path.join)(outDir, dtsName);
|
|
46
|
-
const outMapPath = outPath + ".map";
|
|
47
|
-
(0, fs.mkdirSync)((0, path.dirname)(outPath), { recursive: true });
|
|
48
|
-
let dtsCode = result.declaration ?? "";
|
|
49
|
-
if (declarationMap && result.declarationMap) {
|
|
50
|
-
dtsCode += `\n//# sourceMappingURL=${(0, path.basename)(dtsName)}.map\n`;
|
|
51
|
-
(0, fs.writeFileSync)(outMapPath, JSON.stringify(result.declarationMap), "utf-8");
|
|
26
|
+
const host = _typescript_typescript6.default.createCompilerHost(configFile.options);
|
|
27
|
+
const outDir = configFile.options.outDir ?? dir ?? "lib";
|
|
28
|
+
const parsed = _typescript_typescript6.default.parseJsonConfigFileContent({
|
|
29
|
+
...configFile,
|
|
30
|
+
include,
|
|
31
|
+
exclude: [...require_utils_array.toArray(exclude), "*.ts"],
|
|
32
|
+
compilerOptions: {
|
|
33
|
+
...configFile.options,
|
|
34
|
+
outDir,
|
|
35
|
+
noEmit: false,
|
|
36
|
+
emitDeclarationOnly: true,
|
|
37
|
+
declaration: true,
|
|
38
|
+
declarationMap
|
|
52
39
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
40
|
+
}, _typescript_typescript6.default.sys, cwd);
|
|
41
|
+
const program = _typescript_typescript6.default.createProgram(parsed.fileNames, {
|
|
42
|
+
...configFile.options,
|
|
43
|
+
outDir,
|
|
44
|
+
noEmit: false,
|
|
45
|
+
emitDeclarationOnly: true,
|
|
46
|
+
declaration: true,
|
|
47
|
+
declarationMap
|
|
48
|
+
}, host);
|
|
49
|
+
const emitResult = program.emit();
|
|
50
|
+
const errors = _typescript_typescript6.default.getPreEmitDiagnostics(program).concat(emitResult.diagnostics).filter((d) => d.category === _typescript_typescript6.default.DiagnosticCategory.Error);
|
|
51
|
+
if (errors.length > 0) console.error(_typescript_typescript6.default.formatDiagnosticsWithColorAndContext(errors, host));
|
|
64
52
|
await (0, tsc_alias.replaceTscAliasPaths)({
|
|
65
53
|
configFile: tsconfigPath,
|
|
66
54
|
outDir
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typescript.cjs","names":["toArray","
|
|
1
|
+
{"version":3,"file":"typescript.cjs","names":["toArray","ts","existsSync","readTsConfig"],"sources":["../../../src/rolldown-config/plugins/typescript.ts"],"sourcesContent":["import { existsSync } from 'node:fs';\n\nimport ts from '@typescript/typescript6';\nimport type { RolldownPluginOption } from 'rolldown';\nimport { replaceTscAliasPaths } from 'tsc-alias';\n\nimport { toArray } from '#utils';\n\nimport { DEFAULT_DIR } from '../constants';\nimport { readTsConfig } from './typescript.config';\n\ntype Props = {\n exclude?: string | string[];\n include?: Record<string, string>;\n declarationMap?: boolean;\n dir?: string;\n};\n\nexport const typescript = ({\n exclude,\n include,\n declarationMap,\n dir,\n}: Props = {}): RolldownPluginOption => {\n let done = false;\n\n return {\n name: 'bemedev-dts',\n options(opts) {\n const existing = toArray(opts.external).filter(\n v => typeof v === 'string' || v instanceof RegExp,\n );\n opts.external = [...existing, 'source-map-support'];\n return opts;\n },\n closeBundle: {\n order: 'pre',\n async handler() {\n if (done) return;\n const cwd = process.cwd();\n\n const tsconfigPath = ts.findConfigFile(\n cwd,\n existsSync,\n 'tsconfig.json',\n )!;\n\n const configFile = readTsConfig(tsconfigPath);\n const host = ts.createCompilerHost(configFile.options);\n const outDir = configFile.options.outDir ?? dir ?? DEFAULT_DIR;\n\n const parsed = ts.parseJsonConfigFileContent(\n {\n ...configFile,\n include,\n exclude: [...toArray(exclude), '*.ts'],\n compilerOptions: {\n ...configFile.options,\n outDir,\n noEmit: false,\n emitDeclarationOnly: true,\n declaration: true,\n declarationMap,\n },\n },\n ts.sys,\n cwd,\n );\n\n const program = ts.createProgram(\n parsed.fileNames,\n {\n ...configFile.options,\n outDir,\n noEmit: false,\n emitDeclarationOnly: true,\n declaration: true,\n declarationMap,\n },\n host,\n );\n\n const emitResult = program.emit();\n\n const errors = ts\n .getPreEmitDiagnostics(program)\n .concat(emitResult.diagnostics)\n .filter(d => d.category === ts.DiagnosticCategory.Error);\n\n if (errors.length > 0) {\n console.error(\n ts.formatDiagnosticsWithColorAndContext(errors, host),\n );\n }\n\n await replaceTscAliasPaths({ configFile: tsconfigPath, outDir });\n\n done = true;\n console.log('DTS generation complete');\n },\n },\n };\n};\n"],"mappings":";;;;;;;;;;AAkBA,MAAa,cAAc,EACzB,SACA,SACA,gBACA,QACS,CAAC,MAA4B;CACtC,IAAI,OAAO;CAEX,OAAO;EACL,MAAM;EACN,QAAQ,MAAM;GAIZ,KAAK,WAAW,CAAC,GAHAA,oBAAAA,QAAQ,KAAK,QAAQ,CAAC,CAAC,QACtC,MAAK,OAAO,MAAM,YAAY,aAAa,MAElB,GAAG,oBAAoB;GAClD,OAAO;EACT;EACA,aAAa;GACX,OAAO;GACP,MAAM,UAAU;IACd,IAAI,MAAM;IACV,MAAM,MAAM,QAAQ,IAAI;IAExB,MAAM,eAAeC,wBAAAA,QAAG,eACtB,KACAC,GAAAA,YACA,eACF;IAEA,MAAM,aAAaC,kDAAAA,aAAa,YAAY;IAC5C,MAAM,OAAOF,wBAAAA,QAAG,mBAAmB,WAAW,OAAO;IACrD,MAAM,SAAS,WAAW,QAAQ,UAAU,OAAA;IAE5C,MAAM,SAASA,wBAAAA,QAAG,2BAChB;KACE,GAAG;KACH;KACA,SAAS,CAAC,GAAGD,oBAAAA,QAAQ,OAAO,GAAG,MAAM;KACrC,iBAAiB;MACf,GAAG,WAAW;MACd;MACA,QAAQ;MACR,qBAAqB;MACrB,aAAa;MACb;KACF;IACF,GACAC,wBAAAA,QAAG,KACH,GACF;IAEA,MAAM,UAAUA,wBAAAA,QAAG,cACjB,OAAO,WACP;KACE,GAAG,WAAW;KACd;KACA,QAAQ;KACR,qBAAqB;KACrB,aAAa;KACb;IACF,GACA,IACF;IAEA,MAAM,aAAa,QAAQ,KAAK;IAEhC,MAAM,SAASA,wBAAAA,QACZ,sBAAsB,OAAO,CAAC,CAC9B,OAAO,WAAW,WAAW,CAAC,CAC9B,QAAO,MAAK,EAAE,aAAaA,wBAAAA,QAAG,mBAAmB,KAAK;IAEzD,IAAI,OAAO,SAAS,GAClB,QAAQ,MACNA,wBAAAA,QAAG,qCAAqC,QAAQ,IAAI,CACtD;IAGF,OAAA,GAAA,UAAA,qBAAA,CAA2B;KAAE,YAAY;KAAc;IAAO,CAAC;IAE/D,OAAO;IACP,QAAQ,IAAI,yBAAyB;GACvC;EACF;CACF;AACF"}
|
|
@@ -1,51 +1,63 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_runtime = require("../../_virtual/_rolldown/runtime.cjs");
|
|
2
3
|
let fs = require("fs");
|
|
3
4
|
let path = require("path");
|
|
4
|
-
let
|
|
5
|
+
let _typescript_typescript6 = require("@typescript/typescript6");
|
|
6
|
+
_typescript_typescript6 = require_runtime.__toESM(_typescript_typescript6, 1);
|
|
5
7
|
//#region src/rolldown-config/plugins/typescript.config.ts
|
|
6
|
-
|
|
7
|
-
return jsonString.replace(/\\"|"(?:\\"|[^"])*"|(\/\/.*|\/\*[\s\S]*?\*\/)/g, (m, g) => g ? "" : m);
|
|
8
|
-
}
|
|
9
|
-
function findConfigFile(searchPath, configName = "tsconfig.json") {
|
|
10
|
-
let dir = searchPath;
|
|
11
|
-
while (true) {
|
|
12
|
-
const filePath = (0, path.join)(dir, configName);
|
|
13
|
-
if ((0, fs.existsSync)(filePath)) return filePath;
|
|
14
|
-
const parentDir = (0, path.dirname)(dir);
|
|
15
|
-
if (parentDir === dir) break;
|
|
16
|
-
dir = parentDir;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
const readTsConfig = (path$1) => {
|
|
20
|
-
if (!(0, fs.existsSync)(path$1)) throw new Error(`tsconfig.json not found at ${path$1}`);
|
|
21
|
-
const cleanJson = stripComments((0, fs.readFileSync)(path$1, "utf-8"));
|
|
22
|
-
let config;
|
|
8
|
+
const _readFile = (filePath) => {
|
|
23
9
|
try {
|
|
24
|
-
|
|
25
|
-
} catch
|
|
26
|
-
|
|
10
|
+
return (0, fs.readFileSync)(filePath, "utf-8");
|
|
11
|
+
} catch {
|
|
12
|
+
return;
|
|
27
13
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
14
|
+
};
|
|
15
|
+
const _readDirectory = (rootDir, extensions, _, __, depth) => {
|
|
16
|
+
const results = [];
|
|
17
|
+
const walk = (dir, currentDepth) => {
|
|
18
|
+
if (depth !== void 0 && currentDepth > depth) return;
|
|
19
|
+
let entries;
|
|
20
|
+
try {
|
|
21
|
+
entries = (0, fs.readdirSync)(dir);
|
|
22
|
+
} catch {
|
|
23
|
+
return;
|
|
37
24
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
25
|
+
for (const entry of entries) {
|
|
26
|
+
const fullPath = (0, path.join)(dir, entry);
|
|
27
|
+
let stat;
|
|
28
|
+
try {
|
|
29
|
+
stat = (0, fs.statSync)(fullPath);
|
|
30
|
+
} catch {
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
if (stat.isDirectory()) walk(fullPath, currentDepth + 1);
|
|
34
|
+
else if (!extensions || extensions.some((ext) => entry.endsWith(ext))) results.push(fullPath);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
walk(rootDir, 0);
|
|
38
|
+
return results;
|
|
39
|
+
};
|
|
40
|
+
const _host = {
|
|
41
|
+
useCaseSensitiveFileNames: true,
|
|
42
|
+
readDirectory: _readDirectory,
|
|
43
|
+
fileExists: fs.existsSync,
|
|
44
|
+
readFile: _readFile
|
|
45
|
+
};
|
|
46
|
+
function getConfig(searchPath, configName = "tsconfig.json") {
|
|
47
|
+
const tsconfigPath = _typescript_typescript6.default.findConfigFile(searchPath, fs.existsSync, configName);
|
|
48
|
+
return readTsConfig(tsconfigPath);
|
|
49
|
+
}
|
|
50
|
+
const readTsConfig = (path$1) => {
|
|
51
|
+
const configFile = _typescript_typescript6.default.readConfigFile(path$1, _readFile);
|
|
52
|
+
if (configFile.error) throw new Error(_typescript_typescript6.default.formatDiagnostic(configFile.error, {
|
|
53
|
+
getCanonicalFileName: (f) => f,
|
|
54
|
+
getCurrentDirectory: () => process.cwd(),
|
|
55
|
+
getNewLine: () => "\n"
|
|
56
|
+
}));
|
|
57
|
+
return _typescript_typescript6.default.parseJsonConfigFileContent(configFile.config, _host, (0, path.dirname)(path$1));
|
|
46
58
|
};
|
|
47
59
|
//#endregion
|
|
48
|
-
exports.
|
|
60
|
+
exports.getConfig = getConfig;
|
|
49
61
|
exports.readTsConfig = readTsConfig;
|
|
50
62
|
|
|
51
63
|
//# sourceMappingURL=typescript.config.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typescript.config.cjs","names":["path"],"sources":["../../../src/rolldown-config/plugins/typescript.config.ts"],"sourcesContent":["import { existsSync, readFileSync } from 'node:fs';\nimport {
|
|
1
|
+
{"version":3,"file":"typescript.config.cjs","names":["existsSync","ts","path"],"sources":["../../../src/rolldown-config/plugins/typescript.config.ts"],"sourcesContent":["import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';\nimport { dirname, join } from 'node:path';\n\nimport ts from '@typescript/typescript6';\n\nconst _readFile = (filePath: string): string | undefined => {\n try {\n return readFileSync(filePath, 'utf-8');\n } catch {\n return undefined;\n }\n};\n\nconst _readDirectory: ts.ParseConfigHost['readDirectory'] = (\n rootDir,\n extensions,\n _,\n __,\n depth,\n): string[] => {\n const results: string[] = [];\n\n const walk = (dir: string, currentDepth: number) => {\n if (depth !== undefined && currentDepth > depth) return;\n\n let entries: string[];\n try {\n entries = readdirSync(dir);\n } catch {\n return;\n }\n\n for (const entry of entries) {\n const fullPath = join(dir, entry);\n let stat;\n try {\n stat = statSync(fullPath);\n } catch {\n continue;\n }\n\n if (stat.isDirectory()) {\n walk(fullPath, currentDepth + 1);\n } else if (\n !extensions ||\n extensions.some(ext => entry.endsWith(ext))\n ) {\n results.push(fullPath);\n }\n }\n };\n\n walk(rootDir, 0);\n return results;\n};\n\nconst _host: ts.ParseConfigHost = {\n useCaseSensitiveFileNames: true,\n readDirectory: _readDirectory,\n fileExists: existsSync,\n readFile: _readFile,\n};\n\nexport function getConfig(\n searchPath: string,\n configName: string = 'tsconfig.json',\n) {\n const tsconfigPath = ts.findConfigFile(\n searchPath,\n existsSync,\n configName,\n )!;\n\n const configFile = readTsConfig(tsconfigPath);\n return configFile;\n}\n\nexport const readTsConfig = (path: string) => {\n const configFile = ts.readConfigFile(path, _readFile);\n\n if (configFile.error) {\n throw new Error(\n ts.formatDiagnostic(configFile.error, {\n getCanonicalFileName: f => f,\n getCurrentDirectory: () => process.cwd(),\n getNewLine: () => '\\n',\n }),\n );\n }\n\n const parsedConfig = ts.parseJsonConfigFileContent(\n configFile.config,\n _host,\n dirname(path),\n );\n\n return parsedConfig;\n};\n"],"mappings":";;;;;;;AAKA,MAAM,aAAa,aAAyC;CAC1D,IAAI;EACF,QAAA,GAAA,GAAA,aAAA,CAAoB,UAAU,OAAO;CACvC,QAAQ;EACN;CACF;AACF;AAEA,MAAM,kBACJ,SACA,YACA,GACA,IACA,UACa;CACb,MAAM,UAAoB,CAAC;CAE3B,MAAM,QAAQ,KAAa,iBAAyB;EAClD,IAAI,UAAU,KAAA,KAAa,eAAe,OAAO;EAEjD,IAAI;EACJ,IAAI;GACF,WAAA,GAAA,GAAA,YAAA,CAAsB,GAAG;EAC3B,QAAQ;GACN;EACF;EAEA,KAAK,MAAM,SAAS,SAAS;GAC3B,MAAM,YAAA,GAAA,KAAA,KAAA,CAAgB,KAAK,KAAK;GAChC,IAAI;GACJ,IAAI;IACF,QAAA,GAAA,GAAA,SAAA,CAAgB,QAAQ;GAC1B,QAAQ;IACN;GACF;GAEA,IAAI,KAAK,YAAY,GACnB,KAAK,UAAU,eAAe,CAAC;QAC1B,IACL,CAAC,cACD,WAAW,MAAK,QAAO,MAAM,SAAS,GAAG,CAAC,GAE1C,QAAQ,KAAK,QAAQ;EAEzB;CACF;CAEA,KAAK,SAAS,CAAC;CACf,OAAO;AACT;AAEA,MAAM,QAA4B;CAChC,2BAA2B;CAC3B,eAAe;CACf,YAAYA,GAAAA;CACZ,UAAU;AACZ;AAEA,SAAgB,UACd,YACA,aAAqB,iBACrB;CACA,MAAM,eAAeC,wBAAAA,QAAG,eACtB,YACAD,GAAAA,YACA,UACF;CAGA,OADmB,aAAa,YAChB;AAClB;AAEA,MAAa,gBAAgB,WAAiB;CAC5C,MAAM,aAAaC,wBAAAA,QAAG,eAAeC,QAAM,SAAS;CAEpD,IAAI,WAAW,OACb,MAAM,IAAI,MACRD,wBAAAA,QAAG,iBAAiB,WAAW,OAAO;EACpC,uBAAsB,MAAK;EAC3B,2BAA2B,QAAQ,IAAI;EACvC,kBAAkB;CACpB,CAAC,CACH;CASF,OANqBA,wBAAAA,QAAG,2BACtB,WAAW,QACX,QAAA,GAAA,KAAA,QAAA,CACQC,MAAI,CAGI;AACpB"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
export declare
|
|
3
|
-
|
|
4
|
-
};
|
|
1
|
+
import ts from '@typescript/typescript6';
|
|
2
|
+
export declare function getConfig(searchPath: string, configName?: string): ts.ParsedCommandLine;
|
|
3
|
+
export declare const readTsConfig: (path: string) => ts.ParsedCommandLine;
|
|
@@ -1,49 +1,59 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
1
|
+
import { existsSync, readFileSync, readdirSync, statSync } from "fs";
|
|
2
|
+
import { dirname, join } from "path";
|
|
3
|
+
import ts from "@typescript/typescript6";
|
|
4
4
|
//#region src/rolldown-config/plugins/typescript.config.ts
|
|
5
|
-
|
|
6
|
-
return jsonString.replace(/\\"|"(?:\\"|[^"])*"|(\/\/.*|\/\*[\s\S]*?\*\/)/g, (m, g) => g ? "" : m);
|
|
7
|
-
}
|
|
8
|
-
function findConfigFile(searchPath, configName = "tsconfig.json") {
|
|
9
|
-
let dir = searchPath;
|
|
10
|
-
while (true) {
|
|
11
|
-
const filePath = join(dir, configName);
|
|
12
|
-
if (existsSync(filePath)) return filePath;
|
|
13
|
-
const parentDir = dirname(dir);
|
|
14
|
-
if (parentDir === dir) break;
|
|
15
|
-
dir = parentDir;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
const readTsConfig = (path) => {
|
|
19
|
-
if (!existsSync(path)) throw new Error(`tsconfig.json not found at ${path}`);
|
|
20
|
-
const cleanJson = stripComments(readFileSync(path, "utf-8"));
|
|
21
|
-
let config;
|
|
5
|
+
const _readFile = (filePath) => {
|
|
22
6
|
try {
|
|
23
|
-
|
|
24
|
-
} catch
|
|
25
|
-
|
|
7
|
+
return readFileSync(filePath, "utf-8");
|
|
8
|
+
} catch {
|
|
9
|
+
return;
|
|
26
10
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
11
|
+
};
|
|
12
|
+
const _readDirectory = (rootDir, extensions, _, __, depth) => {
|
|
13
|
+
const results = [];
|
|
14
|
+
const walk = (dir, currentDepth) => {
|
|
15
|
+
if (depth !== void 0 && currentDepth > depth) return;
|
|
16
|
+
let entries;
|
|
17
|
+
try {
|
|
18
|
+
entries = readdirSync(dir);
|
|
19
|
+
} catch {
|
|
20
|
+
return;
|
|
36
21
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
22
|
+
for (const entry of entries) {
|
|
23
|
+
const fullPath = join(dir, entry);
|
|
24
|
+
let stat;
|
|
25
|
+
try {
|
|
26
|
+
stat = statSync(fullPath);
|
|
27
|
+
} catch {
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
if (stat.isDirectory()) walk(fullPath, currentDepth + 1);
|
|
31
|
+
else if (!extensions || extensions.some((ext) => entry.endsWith(ext))) results.push(fullPath);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
walk(rootDir, 0);
|
|
35
|
+
return results;
|
|
36
|
+
};
|
|
37
|
+
const _host = {
|
|
38
|
+
useCaseSensitiveFileNames: true,
|
|
39
|
+
readDirectory: _readDirectory,
|
|
40
|
+
fileExists: existsSync,
|
|
41
|
+
readFile: _readFile
|
|
42
|
+
};
|
|
43
|
+
function getConfig(searchPath, configName = "tsconfig.json") {
|
|
44
|
+
const tsconfigPath = ts.findConfigFile(searchPath, existsSync, configName);
|
|
45
|
+
return readTsConfig(tsconfigPath);
|
|
46
|
+
}
|
|
47
|
+
const readTsConfig = (path) => {
|
|
48
|
+
const configFile = ts.readConfigFile(path, _readFile);
|
|
49
|
+
if (configFile.error) throw new Error(ts.formatDiagnostic(configFile.error, {
|
|
50
|
+
getCanonicalFileName: (f) => f,
|
|
51
|
+
getCurrentDirectory: () => process.cwd(),
|
|
52
|
+
getNewLine: () => "\n"
|
|
53
|
+
}));
|
|
54
|
+
return ts.parseJsonConfigFileContent(configFile.config, _host, dirname(path));
|
|
45
55
|
};
|
|
46
56
|
//#endregion
|
|
47
|
-
export {
|
|
57
|
+
export { getConfig, readTsConfig };
|
|
48
58
|
|
|
49
59
|
//# sourceMappingURL=typescript.config.js.map
|