powerlines 0.23.2 → 0.23.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api--9pVSIbm.d.cts +168 -0
- package/dist/api-DxPACGY4.d.ts +168 -0
- package/dist/api.cjs +3 -3
- package/dist/api.d.cts +16 -7
- package/dist/api.d.ts +16 -7
- package/dist/api.js +2 -2
- package/dist/astro.cjs +8 -8
- package/dist/astro.d.cts +3 -5
- package/dist/astro.d.ts +3 -5
- package/dist/astro.js +5 -5
- package/dist/{chunk-ZFO3FUM4.cjs → chunk-2FLICTDF.cjs} +2 -2
- package/dist/{chunk-JAJ4CI2F.cjs → chunk-3OQXZ5MM.cjs} +2 -2
- package/dist/{chunk-KFRKOIP3.js → chunk-5B6P2VUG.js} +1 -1
- package/dist/{chunk-GNNF5SG6.cjs → chunk-6ACGI52O.cjs} +2 -2
- package/dist/{chunk-JZAQW55G.cjs → chunk-AF5VNWZD.cjs} +2 -2
- package/dist/{chunk-J7MZRPLN.cjs → chunk-AIC2EHPW.cjs} +5 -4
- package/dist/{chunk-3WDMXRK6.cjs → chunk-AYKZK666.cjs} +1 -1
- package/dist/chunk-CHNKTBUA.cjs +32 -0
- package/dist/{chunk-M4QJ2474.cjs → chunk-CTSSNO5L.cjs} +4 -4
- package/dist/{chunk-5A7FM72H.cjs → chunk-GP6XGAJ4.cjs} +2 -2
- package/dist/{chunk-DUYZ3TCT.js → chunk-HLQGKQZY.js} +1 -1
- package/dist/{chunk-LKN52AAX.js → chunk-HNJC47JM.js} +1 -1
- package/dist/{chunk-IGWSCIES.js → chunk-ISLX4Z3L.js} +3 -2
- package/dist/{chunk-J5LKLH5Z.js → chunk-KFSVTJMR.js} +1 -1
- package/dist/{chunk-RWVNX2CP.js → chunk-MI3U2GAT.js} +1 -1
- package/dist/{chunk-4ODWTALP.js → chunk-N3F54RFW.js} +2 -2
- package/dist/{chunk-Q7HBETZW.js → chunk-O2WB6QZ6.js} +1 -1
- package/dist/{chunk-DWV5QAGZ.cjs → chunk-OEKSQ22R.cjs} +2997 -2710
- package/dist/{chunk-WSLPUUGZ.js → chunk-PTZB4LWS.js} +1 -1
- package/dist/{chunk-CPRXGMH2.js → chunk-QSNFMINQ.js} +1 -1
- package/dist/{chunk-YQ76DZYD.cjs → chunk-QUZ4T5AX.cjs} +2 -2
- package/dist/chunk-UTAJPBVT.js +29 -0
- package/dist/{chunk-WG55ZHJL.cjs → chunk-UW3MXOWV.cjs} +2 -2
- package/dist/{chunk-F6BDL4HD.js → chunk-VDBKZJV6.js} +1 -1
- package/dist/{chunk-J3LN5HOC.cjs → chunk-VFLCP3SA.cjs} +2 -2
- package/dist/{chunk-FM4ABZQ2.js → chunk-VT7NVLLU.js} +1 -1
- package/dist/{chunk-WDBPA4RQ.cjs → chunk-VXAKPZ3A.cjs} +2 -2
- package/dist/{chunk-WXU3KLBP.cjs → chunk-XOI5CY62.cjs} +2 -2
- package/dist/{chunk-NH7U3PTV.js → chunk-ZQ7PDXYO.js} +1 -1
- package/dist/{chunk-TNYZH6EG.js → chunk-ZYCPZLIG.js} +2982 -2700
- package/dist/config.d.cts +3 -5
- package/dist/config.d.ts +3 -5
- package/dist/esbuild.cjs +7 -7
- package/dist/esbuild.d.cts +3 -5
- package/dist/esbuild.d.ts +3 -5
- package/dist/esbuild.js +4 -4
- package/dist/farm.cjs +4 -4
- package/dist/farm.d.cts +3 -5
- package/dist/farm.d.ts +3 -5
- package/dist/farm.js +3 -3
- package/dist/index.cjs +54 -33
- package/dist/index.d.cts +191 -39
- package/dist/index.d.ts +191 -39
- package/dist/index.js +18 -17
- package/dist/lib/api-B6hfFxVS.d.ts +167 -0
- package/dist/lib/api-CD2QlMig.d.cts +167 -0
- package/dist/lib/build/esbuild.d.cts +2 -4
- package/dist/lib/build/esbuild.d.ts +2 -4
- package/dist/lib/build/index.d.cts +4 -5
- package/dist/lib/build/index.d.ts +4 -5
- package/dist/lib/build/rolldown.d.cts +2 -4
- package/dist/lib/build/rolldown.d.ts +2 -4
- package/dist/lib/build/rollup.d.cts +2 -4
- package/dist/lib/build/rollup.d.ts +2 -4
- package/dist/lib/build/rspack.d.cts +2 -4
- package/dist/lib/build/rspack.d.ts +2 -4
- package/dist/lib/build/tsup.d.cts +2 -4
- package/dist/lib/build/tsup.d.ts +2 -4
- package/dist/lib/build/unbuild.d.cts +4 -23
- package/dist/lib/build/unbuild.d.ts +4 -23
- package/dist/lib/build/vite.d.cts +2 -4
- package/dist/lib/build/vite.d.ts +2 -4
- package/dist/lib/build/webpack.d.cts +2 -4
- package/dist/lib/build/webpack.d.ts +2 -4
- package/dist/lib/chunk-32Q2PG5D.js +9 -0
- package/dist/lib/chunk-35FGUJFD.cjs +2 -0
- package/dist/lib/{chunk-LIN4KAV3.js → chunk-52VDUP5J.js} +5 -7
- package/dist/lib/chunk-B3EE3VHZ.cjs +127 -0
- package/dist/lib/{chunk-UWHGJ4JS.js → chunk-BLNW3ZQA.js} +483 -1776
- package/dist/lib/chunk-DX2VAXZB.cjs +11 -0
- package/dist/lib/{chunk-VGSV2BEL.cjs → chunk-EFYMNU53.cjs} +6 -12
- package/dist/lib/chunk-FBQIPNRV.cjs +146 -0
- package/dist/lib/chunk-FFT4PWRM.js +1 -0
- package/dist/lib/{chunk-L4NEN725.js → chunk-G7S5PIAC.js} +1 -1
- package/dist/lib/chunk-KFJCWNVG.js +120 -0
- package/dist/lib/chunk-M2U6XIQ2.js +144 -0
- package/dist/lib/chunk-MVIKYHBX.cjs +2 -0
- package/dist/lib/chunk-NYNHNTHT.js +1 -0
- package/dist/lib/{chunk-A5SB72VO.cjs → chunk-PYQADZVV.cjs} +493 -1779
- package/dist/lib/chunk-QP6WX3Q3.js +1190 -0
- package/dist/lib/chunk-S7LLEDQM.cjs +1218 -0
- package/dist/lib/chunk-UHGGYHSK.cjs +175 -0
- package/dist/lib/chunk-YNKFRPUY.js +168 -0
- package/dist/lib/{chunk-ULJVBW4L.cjs → chunk-ZBDVQVUK.cjs} +1 -1
- package/dist/lib/{config-BoGlIhnH.d.cts → config-DTSdCZsw.d.cts} +650 -633
- package/dist/lib/{config-CTej7RMP.d.ts → config-DeUaQYc_.d.ts} +650 -633
- package/dist/lib/config-file.d.cts +4 -5
- package/dist/lib/config-file.d.ts +4 -5
- package/dist/lib/contexts/api-context.cjs +18 -0
- package/dist/lib/contexts/api-context.d.cts +69 -0
- package/dist/lib/contexts/api-context.d.ts +69 -0
- package/dist/lib/contexts/api-context.js +9 -0
- package/dist/lib/contexts/context.cjs +15 -0
- package/dist/lib/contexts/context.d.cts +255 -0
- package/dist/lib/contexts/context.d.ts +255 -0
- package/dist/lib/contexts/context.js +6 -0
- package/dist/lib/contexts/environment-context.cjs +17 -0
- package/dist/lib/contexts/environment-context.d.cts +65 -0
- package/dist/lib/contexts/environment-context.d.ts +65 -0
- package/dist/lib/contexts/environment-context.js +8 -0
- package/dist/lib/contexts/index.cjs +31 -0
- package/dist/lib/contexts/index.d.cts +35 -0
- package/dist/lib/contexts/index.d.ts +35 -0
- package/dist/lib/contexts/index.js +10 -0
- package/dist/lib/contexts/plugin-context.cjs +11 -0
- package/dist/lib/contexts/plugin-context.d.cts +42 -0
- package/dist/lib/contexts/plugin-context.d.ts +42 -0
- package/dist/lib/contexts/plugin-context.js +2 -0
- package/dist/lib/entry.d.cts +2 -4
- package/dist/lib/entry.d.ts +2 -4
- package/dist/lib/index.cjs +96 -74
- package/dist/lib/index.d.cts +26 -23
- package/dist/lib/index.d.ts +26 -23
- package/dist/lib/index.js +18 -12
- package/dist/lib/internal-CpVMJCaU.d.ts +39 -0
- package/dist/lib/internal-ypnrUNZy.d.cts +39 -0
- package/dist/lib/logger.d.cts +4 -5
- package/dist/lib/logger.d.ts +4 -5
- package/dist/lib/typescript/compiler-host.cjs +1 -1
- package/dist/lib/typescript/compiler-host.d.cts +5 -5
- package/dist/lib/typescript/compiler-host.d.ts +5 -5
- package/dist/lib/typescript/compiler-host.js +1 -1
- package/dist/lib/typescript/import-transformer.d.cts +2 -4
- package/dist/lib/typescript/import-transformer.d.ts +2 -4
- package/dist/lib/typescript/index.cjs +29 -24
- package/dist/lib/typescript/index.d.cts +6 -6
- package/dist/lib/typescript/index.d.ts +6 -6
- package/dist/lib/typescript/index.js +3 -2
- package/dist/lib/typescript/isolated-decl.d.cts +2 -1
- package/dist/lib/typescript/isolated-decl.d.ts +2 -1
- package/dist/lib/typescript/program.d.cts +5 -5
- package/dist/lib/typescript/program.d.ts +5 -5
- package/dist/lib/typescript/ts-morph.cjs +11 -0
- package/dist/lib/{create-program.d.ts → typescript/ts-morph.d.cts} +3 -5
- package/dist/lib/{create-program.d.cts → typescript/ts-morph.d.ts} +3 -5
- package/dist/lib/typescript/ts-morph.js +2 -0
- package/dist/lib/unplugin/factory.cjs +8 -4
- package/dist/lib/unplugin/factory.d.cts +27 -10
- package/dist/lib/unplugin/factory.d.ts +27 -10
- package/dist/lib/unplugin/factory.js +7 -3
- package/dist/lib/unplugin/helpers.cjs +11 -0
- package/dist/lib/unplugin/helpers.d.cts +128 -0
- package/dist/lib/unplugin/helpers.d.ts +128 -0
- package/dist/lib/unplugin/helpers.js +2 -0
- package/dist/lib/unplugin/index.cjs +12 -7
- package/dist/lib/unplugin/index.d.cts +6 -8
- package/dist/lib/unplugin/index.d.ts +6 -8
- package/dist/lib/unplugin/index.js +9 -4
- package/dist/lib/unplugin/plugin.cjs +4 -3
- package/dist/lib/unplugin/plugin.d.cts +4 -5
- package/dist/lib/unplugin/plugin.d.ts +4 -5
- package/dist/lib/unplugin/plugin.js +3 -2
- package/dist/lib/unplugin/resolve-id.cjs +2 -2
- package/dist/lib/unplugin/resolve-id.d.cts +5 -5
- package/dist/lib/unplugin/resolve-id.d.ts +5 -5
- package/dist/lib/unplugin/resolve-id.js +1 -1
- package/dist/lib/utilities/bundle.d.cts +2 -4
- package/dist/lib/utilities/bundle.d.ts +2 -4
- package/dist/lib/utilities/cache.d.cts +2 -4
- package/dist/lib/utilities/cache.d.ts +2 -4
- package/dist/lib/utilities/file-header.d.cts +4 -5
- package/dist/lib/utilities/file-header.d.ts +4 -5
- package/dist/lib/utilities/index.cjs +18 -18
- package/dist/lib/utilities/index.d.cts +5 -7
- package/dist/lib/utilities/index.d.ts +5 -7
- package/dist/lib/utilities/index.js +4 -4
- package/dist/lib/utilities/meta.d.cts +4 -5
- package/dist/lib/utilities/meta.d.ts +4 -5
- package/dist/lib/utilities/resolve-path.d.cts +2 -4
- package/dist/lib/utilities/resolve-path.d.ts +2 -4
- package/dist/lib/utilities/resolve.d.cts +2 -4
- package/dist/lib/utilities/resolve.d.ts +2 -4
- package/dist/lib/utilities/source-file.d.cts +2 -4
- package/dist/lib/utilities/source-file.d.ts +2 -4
- package/dist/lib/utilities/source-map.d.cts +2 -4
- package/dist/lib/utilities/source-map.d.ts +2 -4
- package/dist/lib/utilities/worker.d.cts +4 -5
- package/dist/lib/utilities/worker.d.ts +4 -5
- package/dist/lib/utilities/write-file.d.cts +2 -4
- package/dist/lib/utilities/write-file.d.ts +2 -4
- package/dist/next.cjs +8 -8
- package/dist/next.js +5 -5
- package/dist/nuxt.cjs +9 -9
- package/dist/nuxt.js +6 -6
- package/dist/plugin-utils/{context-D1I2JQgs.d.cts → context-DRFZE3XI.d.cts} +535 -518
- package/dist/plugin-utils/{context-D1I2JQgs.d.ts → context-DRFZE3XI.d.ts} +535 -518
- package/dist/plugin-utils/context-helpers.d.cts +2 -4
- package/dist/plugin-utils/context-helpers.d.ts +2 -4
- package/dist/plugin-utils/enforce.d.cts +2 -4
- package/dist/plugin-utils/enforce.d.ts +2 -4
- package/dist/plugin-utils/extend.d.cts +2 -4
- package/dist/plugin-utils/extend.d.ts +2 -4
- package/dist/plugin-utils/get-config-path.d.cts +2 -4
- package/dist/plugin-utils/get-config-path.d.ts +2 -4
- package/dist/plugin-utils/helpers.d.cts +2 -4
- package/dist/plugin-utils/helpers.d.ts +2 -4
- package/dist/plugin-utils/index.d.cts +3 -5
- package/dist/plugin-utils/index.d.ts +3 -5
- package/dist/plugin-utils/merge.d.cts +4 -5
- package/dist/plugin-utils/merge.d.ts +4 -5
- package/dist/plugin-utils/paths.d.cts +2 -4
- package/dist/plugin-utils/paths.d.ts +2 -4
- package/dist/{resolved-DYLxPDut.d.cts → resolved-C00CJgsk.d.cts} +128 -9
- package/dist/{resolved-D1ySEdUv.d.ts → resolved-DKFZ11S7.d.ts} +128 -9
- package/dist/rolldown.cjs +7 -7
- package/dist/rolldown.d.cts +3 -5
- package/dist/rolldown.d.ts +3 -5
- package/dist/rolldown.js +4 -4
- package/dist/rollup.cjs +7 -7
- package/dist/rollup.d.cts +3 -5
- package/dist/rollup.d.ts +3 -5
- package/dist/rollup.js +4 -4
- package/dist/rspack.cjs +7 -7
- package/dist/rspack.d.cts +3 -5
- package/dist/rspack.d.ts +3 -5
- package/dist/rspack.js +4 -4
- package/dist/tsup.cjs +8 -8
- package/dist/tsup.js +5 -5
- package/dist/types/api.cjs +4 -0
- package/dist/types/api.d.cts +36 -0
- package/dist/types/api.d.ts +36 -0
- package/dist/types/api.js +1 -0
- package/dist/types/babel.d.cts +3 -5
- package/dist/types/babel.d.ts +3 -5
- package/dist/types/build.d.cts +26 -1
- package/dist/types/build.d.ts +26 -1
- package/dist/types/commands.d.cts +3 -5
- package/dist/types/commands.d.ts +3 -5
- package/dist/types/config.d.cts +3 -5
- package/dist/types/config.d.ts +3 -5
- package/dist/types/context.d.cts +3 -5
- package/dist/types/context.d.ts +3 -5
- package/dist/types/{vfs.cjs → fs.cjs} +3 -3
- package/dist/types/{vfs.d.cts → fs.d.cts} +54 -35
- package/dist/types/{vfs.d.ts → fs.d.ts} +54 -35
- package/dist/types/fs.js +2 -0
- package/dist/types/hooks.d.cts +3 -5
- package/dist/types/hooks.d.ts +3 -5
- package/dist/types/index.cjs +9 -8
- package/dist/types/index.d.cts +8 -9
- package/dist/types/index.d.ts +8 -9
- package/dist/types/index.js +3 -2
- package/dist/types/internal.d.cts +46 -9
- package/dist/types/internal.d.ts +46 -9
- package/dist/types/plugin.d.cts +3 -5
- package/dist/types/plugin.d.ts +3 -5
- package/dist/types/resolved.d.cts +3 -5
- package/dist/types/resolved.d.ts +3 -5
- package/dist/types/tsconfig.d.cts +8 -1
- package/dist/types/tsconfig.d.ts +8 -1
- package/dist/types/typedoc.d.cts +3 -1
- package/dist/types/typedoc.d.ts +3 -1
- package/dist/types/unplugin.d.cts +22 -11
- package/dist/types/unplugin.d.ts +22 -11
- package/dist/unloader.cjs +7 -7
- package/dist/unloader.d.cts +12 -14
- package/dist/unloader.d.ts +12 -14
- package/dist/unloader.js +4 -4
- package/dist/unplugin.cjs +18 -18
- package/dist/unplugin.d.cts +6 -9
- package/dist/unplugin.d.ts +6 -9
- package/dist/unplugin.js +15 -15
- package/dist/vite.cjs +7 -7
- package/dist/vite.d.cts +3 -5
- package/dist/vite.d.ts +3 -5
- package/dist/vite.js +4 -4
- package/dist/webpack.cjs +7 -7
- package/dist/webpack.d.cts +3 -5
- package/dist/webpack.d.ts +3 -5
- package/dist/webpack.js +4 -4
- package/package.json +39 -11
- package/schemas/fs.capnp +73 -15
- package/dist/chunk-RODEAGIJ.cjs +0 -32
- package/dist/chunk-SKLSRHBU.js +0 -29
- package/dist/hooks-D2UGCryi.d.ts +0 -28
- package/dist/hooks-DJG3B-Hw.d.cts +0 -28
- package/dist/lib/create-program.cjs +0 -11
- package/dist/lib/create-program.js +0 -2
- package/dist/lib/hooks-CDLPWf7j.d.cts +0 -28
- package/dist/lib/hooks-Cn-IqwYp.d.ts +0 -28
- package/dist/types/vfs.js +0 -2
- /package/dist/{chunk-KIKTWMI3.cjs → chunk-2NCILNCH.cjs} +0 -0
- /package/dist/{chunk-XVLT2RQ2.js → chunk-BLNT5INX.js} +0 -0
- /package/dist/{lib/chunk-RJ4277VZ.cjs → chunk-GRU7B3QM.cjs} +0 -0
- /package/dist/{lib/chunk-ZBLDAREE.js → chunk-T2P533I5.js} +0 -0
- /package/dist/lib/{chunk-CGYAL3S2.cjs → chunk-4EIXDLFP.cjs} +0 -0
- /package/dist/lib/{chunk-CXRSMYEX.js → chunk-RD5AUWXN.js} +0 -0
|
@@ -1,220 +1,135 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { getFileHeader } from './chunk-GANVMM73.js';
|
|
3
|
-
import { CACHE_HASH_LENGTH, PROJECT_ROOT_HASH_LENGTH, getPrefixedProjectRootHash, getChecksum, writeMetaFile } from './chunk-YH5GOJS3.js';
|
|
4
|
-
import { handleResolveId } from './chunk-L4NEN725.js';
|
|
5
|
-
import { getParsedTypeScriptConfig, getTsconfigFilePath, isIncludeMatchFound } from './chunk-YOENMDZY.js';
|
|
1
|
+
import { CACHE_HASH_LENGTH, PROJECT_ROOT_HASH_LENGTH, getPrefixedProjectRootHash, getChecksum } from './chunk-YH5GOJS3.js';
|
|
6
2
|
import { loadWorkspaceConfig, loadUserConfigFile } from './chunk-ZPIKFR7Z.js';
|
|
7
3
|
import { extendLog, createLog } from './chunk-ENRLU4UR.js';
|
|
8
|
-
import {
|
|
9
|
-
import { resolveEntriesSync, getUniqueEntries, replacePathTokens } from './chunk-XZFEHPYE.js';
|
|
4
|
+
import { resolveEntriesSync, getUniqueEntries } from './chunk-XZFEHPYE.js';
|
|
10
5
|
import { __name } from './chunk-SHUYVCID.js';
|
|
11
6
|
import { LogLevelLabel } from '@storm-software/config-tools/types';
|
|
12
|
-
import { relativeToWorkspaceRoot, getWorkspaceRoot } from '@stryke/fs/get-workspace-root';
|
|
13
|
-
import { tsconfigPathsToRegExp } from 'bundle-require';
|
|
14
|
-
import { transformAsync } from '@babel/core';
|
|
15
|
-
import { formatLogMessage } from '@storm-software/config-tools/logger/console';
|
|
16
7
|
import { toArray } from '@stryke/convert/to-array';
|
|
17
|
-
import { copyFiles } from '@stryke/fs/copy-file';
|
|
18
|
-
import { existsSync } from '@stryke/fs/exists';
|
|
19
|
-
import { createDirectory } from '@stryke/fs/helpers';
|
|
20
|
-
import { install } from '@stryke/fs/install';
|
|
21
|
-
import { listFiles } from '@stryke/fs/list-files';
|
|
22
|
-
import { isPackageExists, isPackageListed, doesPackageMatch, getPackageListing } from '@stryke/fs/package-fns';
|
|
23
|
-
import { resolvePackage } from '@stryke/fs/resolve';
|
|
24
|
-
import { appendPath } from '@stryke/path/append';
|
|
25
|
-
import { joinPaths as joinPaths$1 } from '@stryke/path/join-paths';
|
|
26
|
-
import { replacePath } from '@stryke/path/replace';
|
|
27
|
-
import { isError } from '@stryke/type-checks/is-error';
|
|
28
|
-
import { isFunction } from '@stryke/type-checks/is-function';
|
|
29
|
-
import { isNumber } from '@stryke/type-checks/is-number';
|
|
30
|
-
import { isPromiseLike } from '@stryke/type-checks/is-promise';
|
|
31
|
-
import { isSet } from '@stryke/type-checks/is-set';
|
|
32
|
-
import { isSetObject } from '@stryke/type-checks/is-set-object';
|
|
33
|
-
import { isSetString } from '@stryke/type-checks/is-set-string';
|
|
34
|
-
import chalk4 from 'chalk';
|
|
35
|
-
import defu2, { defu } from 'defu';
|
|
36
|
-
import Handlebars from 'handlebars';
|
|
37
|
-
import { declare } from '@babel/helper-plugin-utils';
|
|
38
|
-
import * as t from '@babel/types';
|
|
39
|
-
import { titleCase } from '@stryke/string-format/title-case';
|
|
40
8
|
import { getEnvPaths } from '@stryke/env/get-env-paths';
|
|
9
|
+
import { existsSync } from '@stryke/fs/exists';
|
|
10
|
+
import { relativeToWorkspaceRoot } from '@stryke/fs/get-workspace-root';
|
|
41
11
|
import { readJsonFile } from '@stryke/fs/json';
|
|
12
|
+
import { resolvePackage } from '@stryke/fs/resolve';
|
|
42
13
|
import { murmurhash } from '@stryke/hash/murmurhash';
|
|
43
14
|
import { getUnique } from '@stryke/helpers/get-unique';
|
|
44
15
|
import { omit } from '@stryke/helpers/omit';
|
|
45
16
|
import { StormJSON } from '@stryke/json/storm-json';
|
|
46
|
-
import {
|
|
17
|
+
import { appendPath } from '@stryke/path/append';
|
|
47
18
|
import { isAbsolutePath, isAbsolute } from '@stryke/path/is-type';
|
|
48
19
|
import { joinPaths } from '@stryke/path/join';
|
|
20
|
+
import { replacePath } from '@stryke/path/replace';
|
|
21
|
+
import { titleCase } from '@stryke/string-format/title-case';
|
|
49
22
|
import { isNull } from '@stryke/type-checks/is-null';
|
|
23
|
+
import { isSetObject } from '@stryke/type-checks/is-set-object';
|
|
24
|
+
import { isSetString } from '@stryke/type-checks/is-set-string';
|
|
50
25
|
import { isString } from '@stryke/type-checks/is-string';
|
|
51
26
|
import { uuid } from '@stryke/unique-id/uuid';
|
|
52
|
-
import
|
|
27
|
+
import defu2 from 'defu';
|
|
28
|
+
import { joinPaths as joinPaths$1 } from '@stryke/path/join-paths';
|
|
29
|
+
import { createJiti } from 'jiti';
|
|
30
|
+
import { isFunction } from '@stryke/type-checks/is-function';
|
|
31
|
+
import { isUndefined } from '@stryke/type-checks/is-undefined';
|
|
53
32
|
import * as $ from '@stryke/capnp';
|
|
54
33
|
import { bufferToString } from '@stryke/convert/buffer-to-string';
|
|
55
34
|
import { readFileBuffer, readFileBufferSync, writeFileBuffer } from '@stryke/fs/buffer';
|
|
35
|
+
import { findFileDotExtensionSafe, findFilePath } from '@stryke/path/file-path-fns';
|
|
56
36
|
import { prettyBytes } from '@stryke/string-format/pretty-bytes';
|
|
57
37
|
import { isBuffer } from '@stryke/type-checks/is-buffer';
|
|
58
38
|
import { Blob } from 'node:buffer';
|
|
59
|
-
import
|
|
39
|
+
import _fs from 'node:fs';
|
|
60
40
|
import { resolveConfig, format } from 'prettier';
|
|
61
|
-
import { isUndefined } from '@stryke/type-checks/is-undefined';
|
|
62
41
|
import { isParentPath } from '@stryke/path/is-parent-path';
|
|
63
42
|
import { Volume } from 'memfs/lib/node/volume';
|
|
64
43
|
import { Union } from 'unionfs';
|
|
65
|
-
import { createJiti } from 'jiti';
|
|
66
|
-
import { isObject } from '@stryke/type-checks/is-object';
|
|
67
|
-
import ts, { createProgram, createCompilerHost, getPreEmitDiagnostics, getLineAndCharacterOfPosition, flattenDiagnosticMessageText } from 'typescript';
|
|
68
|
-
import { getPackageName, hasPackageVersion, getPackageVersion } from '@stryke/string-format/package';
|
|
69
|
-
import { getObjectDiff } from '@donedeal0/superdiff';
|
|
70
|
-
import { loadTsConfig } from '@stryke/fs/tsconfig';
|
|
71
44
|
|
|
72
|
-
function
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
45
|
+
function resolveOptions(options) {
|
|
46
|
+
return defu2(options, {
|
|
47
|
+
interopDefault: true,
|
|
48
|
+
fsCache: options.mode !== "development" ? joinPaths$1(options.cacheDir, "jiti") : false,
|
|
49
|
+
moduleCache: options.mode !== "development"
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
__name(resolveOptions, "resolveOptions");
|
|
53
|
+
function createPluginResolver(options) {
|
|
54
|
+
return createJiti(joinPaths$1(options.workspaceRoot, options.projectRoot), resolveOptions({
|
|
55
|
+
...options
|
|
56
|
+
}));
|
|
57
|
+
}
|
|
58
|
+
__name(createPluginResolver, "createPluginResolver");
|
|
59
|
+
function createResolver(options) {
|
|
60
|
+
const baseResolver = createJiti(joinPaths$1(options.workspaceRoot, options.projectRoot), resolveOptions(options));
|
|
61
|
+
baseResolver.plugin = createPluginResolver(options);
|
|
62
|
+
return baseResolver;
|
|
84
63
|
}
|
|
85
|
-
__name(
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
"
|
|
90
|
-
|
|
91
|
-
"
|
|
92
|
-
"
|
|
93
|
-
"
|
|
94
|
-
"
|
|
95
|
-
|
|
96
|
-
"
|
|
97
|
-
"
|
|
98
|
-
"jest.requireActual",
|
|
99
|
-
"jest.requireMock",
|
|
100
|
-
// Older Jest methods
|
|
101
|
-
"require.requireActual",
|
|
102
|
-
"require.requireMock"
|
|
64
|
+
__name(createResolver, "createResolver");
|
|
65
|
+
|
|
66
|
+
// src/types/commands.ts
|
|
67
|
+
var SUPPORTED_COMMANDS = [
|
|
68
|
+
"new",
|
|
69
|
+
"clean",
|
|
70
|
+
"prepare",
|
|
71
|
+
"lint",
|
|
72
|
+
"test",
|
|
73
|
+
"build",
|
|
74
|
+
"docs",
|
|
75
|
+
"deploy",
|
|
76
|
+
"finalize"
|
|
103
77
|
];
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
}
|
|
109
|
-
if (!t.isIdentifier(node) || pattern.includes(".")) {
|
|
110
|
-
return false;
|
|
111
|
-
}
|
|
112
|
-
const name = pattern.split(".")[0];
|
|
113
|
-
return node.name === name;
|
|
78
|
+
|
|
79
|
+
// src/plugin-utils/helpers.ts
|
|
80
|
+
function isPlugin(value) {
|
|
81
|
+
return isSetObject(value) && "name" in value && isSetString(value.name) && (isUndefined(value.applyToEnvironment) || "applyToEnvironment" in value && isFunction(value.applyToEnvironment)) && (isUndefined(value.dedupe) || "dedupe" in value && isFunction(value.dedupe)) && (isUndefined(value.dependsOn) || "dependsOn" in value && Array.isArray(value.dependsOn) && value.dependsOn.every(isPluginConfig)) && SUPPORTED_COMMANDS.every((command) => isUndefined(value[command]) || command in value && (isFunction(value[command]) || isSetObject(value[command]) && "handler" in value[command] && isFunction(value[command].handler)));
|
|
114
82
|
}
|
|
115
|
-
__name(
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
return
|
|
138
|
-
let moduleResolverVisited = /* @__PURE__ */ new Set();
|
|
139
|
-
return {
|
|
140
|
-
name: "powerlines:module-resolver",
|
|
141
|
-
manipulateOptions(opts) {
|
|
142
|
-
opts.filename ??= "unknown";
|
|
143
|
-
},
|
|
144
|
-
pre() {
|
|
145
|
-
moduleResolverVisited = /* @__PURE__ */ new Set();
|
|
146
|
-
},
|
|
147
|
-
visitor: {
|
|
148
|
-
Program: {
|
|
149
|
-
enter(programPath, state) {
|
|
150
|
-
programPath.traverse(importVisitors, {
|
|
151
|
-
...state,
|
|
152
|
-
context,
|
|
153
|
-
moduleResolverVisited,
|
|
154
|
-
api
|
|
155
|
-
});
|
|
156
|
-
},
|
|
157
|
-
exit(programPath, state) {
|
|
158
|
-
programPath.traverse(importVisitors, {
|
|
159
|
-
...state,
|
|
160
|
-
context,
|
|
161
|
-
moduleResolverVisited,
|
|
162
|
-
api
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
},
|
|
167
|
-
post() {
|
|
168
|
-
moduleResolverVisited.clear();
|
|
169
|
-
}
|
|
170
|
-
};
|
|
171
|
-
}, "builder"));
|
|
172
|
-
}, "moduleResolverBabelPlugin");
|
|
173
|
-
var DEFAULT_ENVIRONMENT = "default";
|
|
174
|
-
function createEnvironment(name, userConfig) {
|
|
175
|
-
return defu2(userConfig.environments?.[name] ?? {}, {
|
|
176
|
-
name,
|
|
177
|
-
title: userConfig.title || titleCase(userConfig.name),
|
|
178
|
-
ssr: false,
|
|
179
|
-
mainFields: userConfig.build?.platform === "browser" ? [
|
|
180
|
-
"browser",
|
|
181
|
-
"module",
|
|
182
|
-
"jsnext:main",
|
|
183
|
-
"jsnext"
|
|
184
|
-
] : [
|
|
185
|
-
"module",
|
|
186
|
-
"jsnext:main",
|
|
187
|
-
"jsnext"
|
|
188
|
-
],
|
|
189
|
-
extensions: [
|
|
190
|
-
".mjs",
|
|
191
|
-
".js",
|
|
192
|
-
".mts",
|
|
193
|
-
".ts",
|
|
194
|
-
".jsx",
|
|
195
|
-
".tsx",
|
|
196
|
-
".json"
|
|
197
|
-
],
|
|
198
|
-
consumer: userConfig.build?.platform === "browser" ? "client" : "server",
|
|
199
|
-
preview: userConfig.build?.platform === "browser" ? {
|
|
200
|
-
port: 5173,
|
|
201
|
-
open: true,
|
|
202
|
-
strictPort: false,
|
|
203
|
-
// https: false,
|
|
204
|
-
host: "localhost",
|
|
205
|
-
allowedHosts: [
|
|
206
|
-
"."
|
|
207
|
-
],
|
|
208
|
-
cors: true,
|
|
209
|
-
headers: {}
|
|
210
|
-
} : void 0
|
|
211
|
-
}, userConfig);
|
|
83
|
+
__name(isPlugin, "isPlugin");
|
|
84
|
+
function isPluginConfigObject(value) {
|
|
85
|
+
return isSetObject(value) && "plugin" in value && ((isSetString(value.plugin) || isFunction(value.plugin)) && "options" in value && isSetObject(value.options) || isPlugin(value.plugin));
|
|
86
|
+
}
|
|
87
|
+
__name(isPluginConfigObject, "isPluginConfigObject");
|
|
88
|
+
function isPluginConfigTuple(value) {
|
|
89
|
+
return Array.isArray(value) && (value.length === 1 || value.length === 2) && ((isSetString(value[0]) || isFunction(value[0])) && value.length > 1 && isSetObject(value[1]) || isPlugin(value[0]));
|
|
90
|
+
}
|
|
91
|
+
__name(isPluginConfigTuple, "isPluginConfigTuple");
|
|
92
|
+
function isPluginConfig(value) {
|
|
93
|
+
return isSetString(value) || isFunction(value) || isPlugin(value) || isPluginConfigObject(value) || isPluginConfigTuple(value);
|
|
94
|
+
}
|
|
95
|
+
__name(isPluginConfig, "isPluginConfig");
|
|
96
|
+
function isPluginHookFunction(value) {
|
|
97
|
+
return isFunction(value) || isSetObject(value) && "handler" in value && isFunction(value.handler);
|
|
98
|
+
}
|
|
99
|
+
__name(isPluginHookFunction, "isPluginHookFunction");
|
|
100
|
+
function isPluginHookObject(value) {
|
|
101
|
+
return isSetObject(value) && "handler" in value && isFunction(value.handler);
|
|
102
|
+
}
|
|
103
|
+
__name(isPluginHookObject, "isPluginHookObject");
|
|
104
|
+
function isPluginHook(value) {
|
|
105
|
+
return isPluginHookFunction(value) || isPluginHookObject(value);
|
|
212
106
|
}
|
|
213
|
-
__name(
|
|
214
|
-
function
|
|
215
|
-
return
|
|
107
|
+
__name(isPluginHook, "isPluginHook");
|
|
108
|
+
function getHookHandler(pluginHook) {
|
|
109
|
+
return isFunction(pluginHook) ? pluginHook : pluginHook.handler;
|
|
110
|
+
}
|
|
111
|
+
__name(getHookHandler, "getHookHandler");
|
|
112
|
+
function isHookExternal(hook) {
|
|
113
|
+
return hook.startsWith("vite:") || hook.startsWith("esbuild:") || hook.startsWith("rolldown:") || hook.startsWith("rollup:") || hook.startsWith("webpack:") || hook.startsWith("rspack:") || hook.startsWith("farm:");
|
|
114
|
+
}
|
|
115
|
+
__name(isHookExternal, "isHookExternal");
|
|
116
|
+
function checkDedupe(plugin, plugins) {
|
|
117
|
+
return plugin.dedupe === false || plugins.some((p) => p.dedupe !== false && (isFunction(p.dedupe) && p.dedupe(plugin) || p.name === plugin.name));
|
|
118
|
+
}
|
|
119
|
+
__name(checkDedupe, "checkDedupe");
|
|
120
|
+
function addPluginHook(context, plugin, pluginHook, hooksList) {
|
|
121
|
+
if (!checkDedupe(plugin, hooksList.map((hook) => hook.plugin))) {
|
|
122
|
+
hooksList.push(isFunction(pluginHook) ? {
|
|
123
|
+
plugin,
|
|
124
|
+
handler: getHookHandler(pluginHook).bind(context)
|
|
125
|
+
} : {
|
|
126
|
+
plugin,
|
|
127
|
+
...pluginHook,
|
|
128
|
+
handler: getHookHandler(pluginHook).bind(context)
|
|
129
|
+
});
|
|
130
|
+
}
|
|
216
131
|
}
|
|
217
|
-
__name(
|
|
132
|
+
__name(addPluginHook, "addPluginHook");
|
|
218
133
|
BigInt("0xa56c61324b9d6e49");
|
|
219
134
|
var FileMetadata_KeyValuePair = class extends $.Struct {
|
|
220
135
|
static {
|
|
@@ -249,12 +164,12 @@ var FileMetadata = class _FileMetadata extends $.Struct {
|
|
|
249
164
|
static _capnp = {
|
|
250
165
|
displayName: "FileMetadata",
|
|
251
166
|
id: "8e2cab5d7e28c7b3",
|
|
252
|
-
size: new $.ObjectSize(
|
|
253
|
-
|
|
167
|
+
size: new $.ObjectSize(8, 4),
|
|
168
|
+
defaultType: "normal"
|
|
254
169
|
};
|
|
255
170
|
static _Properties;
|
|
256
171
|
/**
|
|
257
|
-
* The
|
|
172
|
+
* The type of the file.
|
|
258
173
|
*
|
|
259
174
|
*/
|
|
260
175
|
get id() {
|
|
@@ -267,14 +182,14 @@ var FileMetadata = class _FileMetadata extends $.Struct {
|
|
|
267
182
|
* The output mode of the file.
|
|
268
183
|
*
|
|
269
184
|
*/
|
|
270
|
-
get
|
|
271
|
-
return $.utils.getText(1, this, _FileMetadata._capnp.
|
|
185
|
+
get type() {
|
|
186
|
+
return $.utils.getText(1, this, _FileMetadata._capnp.defaultType);
|
|
272
187
|
}
|
|
273
|
-
set
|
|
188
|
+
set type(value) {
|
|
274
189
|
$.utils.setText(1, value, this);
|
|
275
190
|
}
|
|
276
191
|
/**
|
|
277
|
-
*
|
|
192
|
+
* The timestamp representing the file's creation date.
|
|
278
193
|
*
|
|
279
194
|
*/
|
|
280
195
|
get mode() {
|
|
@@ -283,6 +198,16 @@ var FileMetadata = class _FileMetadata extends $.Struct {
|
|
|
283
198
|
set mode(value) {
|
|
284
199
|
$.utils.setText(2, value, this);
|
|
285
200
|
}
|
|
201
|
+
/**
|
|
202
|
+
* Additional metadata associated with the file.
|
|
203
|
+
*
|
|
204
|
+
*/
|
|
205
|
+
get timestamp() {
|
|
206
|
+
return $.utils.getUint32(0, this);
|
|
207
|
+
}
|
|
208
|
+
set timestamp(value) {
|
|
209
|
+
$.utils.setUint32(0, value, this);
|
|
210
|
+
}
|
|
286
211
|
_adoptProperties(value) {
|
|
287
212
|
$.utils.adopt(value, $.utils.getPointer(3, this));
|
|
288
213
|
}
|
|
@@ -305,33 +230,214 @@ var FileMetadata = class _FileMetadata extends $.Struct {
|
|
|
305
230
|
return "FileMetadata_" + super.toString();
|
|
306
231
|
}
|
|
307
232
|
};
|
|
308
|
-
var
|
|
233
|
+
var ChunkData = class extends $.Struct {
|
|
309
234
|
static {
|
|
310
|
-
__name(this, "
|
|
235
|
+
__name(this, "ChunkData");
|
|
311
236
|
}
|
|
312
237
|
static _capnp = {
|
|
313
|
-
displayName: "
|
|
314
|
-
id: "
|
|
315
|
-
size: new $.ObjectSize(
|
|
238
|
+
displayName: "ChunkData",
|
|
239
|
+
id: "84076f13b057f83a",
|
|
240
|
+
size: new $.ObjectSize(8, 4)
|
|
316
241
|
};
|
|
317
242
|
/**
|
|
318
|
-
* An additional
|
|
243
|
+
* An additional name for the file.
|
|
319
244
|
*
|
|
320
245
|
*/
|
|
321
|
-
get
|
|
246
|
+
get id() {
|
|
322
247
|
return $.utils.getText(0, this);
|
|
323
248
|
}
|
|
324
|
-
set
|
|
249
|
+
set id(value) {
|
|
250
|
+
$.utils.setText(0, value, this);
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Files that are implicitly loaded after one of the specified files.
|
|
254
|
+
*
|
|
255
|
+
*/
|
|
256
|
+
get name() {
|
|
257
|
+
return $.utils.getText(1, this);
|
|
258
|
+
}
|
|
259
|
+
set name(value) {
|
|
260
|
+
$.utils.setText(1, value, this);
|
|
261
|
+
}
|
|
262
|
+
_adoptImplicitlyLoadedAfterOneOf(value) {
|
|
263
|
+
$.utils.adopt(value, $.utils.getPointer(2, this));
|
|
264
|
+
}
|
|
265
|
+
_disownImplicitlyLoadedAfterOneOf() {
|
|
266
|
+
return $.utils.disown(this.implicitlyLoadedAfterOneOf);
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* The importer of the file.
|
|
270
|
+
*
|
|
271
|
+
*/
|
|
272
|
+
get implicitlyLoadedAfterOneOf() {
|
|
273
|
+
return $.utils.getList(2, $.TextList, this);
|
|
274
|
+
}
|
|
275
|
+
_hasImplicitlyLoadedAfterOneOf() {
|
|
276
|
+
return !$.utils.isNull($.utils.getPointer(2, this));
|
|
277
|
+
}
|
|
278
|
+
_initImplicitlyLoadedAfterOneOf(length) {
|
|
279
|
+
return $.utils.initList(2, $.TextList, length, this);
|
|
280
|
+
}
|
|
281
|
+
set implicitlyLoadedAfterOneOf(value) {
|
|
282
|
+
$.utils.copyFrom(value, $.utils.getPointer(2, this));
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* The signature preservation mode for the file.
|
|
286
|
+
*
|
|
287
|
+
*/
|
|
288
|
+
get importer() {
|
|
289
|
+
return $.utils.getText(3, this);
|
|
290
|
+
}
|
|
291
|
+
set importer(value) {
|
|
292
|
+
$.utils.setText(3, value, this);
|
|
293
|
+
}
|
|
294
|
+
get preserveSignature() {
|
|
295
|
+
return $.utils.getUint16(0, this);
|
|
296
|
+
}
|
|
297
|
+
set preserveSignature(value) {
|
|
298
|
+
$.utils.setUint16(0, value, this);
|
|
299
|
+
}
|
|
300
|
+
toString() {
|
|
301
|
+
return "ChunkData_" + super.toString();
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
var PrebuiltData = class extends $.Struct {
|
|
305
|
+
static {
|
|
306
|
+
__name(this, "PrebuiltData");
|
|
307
|
+
}
|
|
308
|
+
static _capnp = {
|
|
309
|
+
displayName: "PrebuiltData",
|
|
310
|
+
id: "c5b1a6ca696328ee",
|
|
311
|
+
size: new $.ObjectSize(0, 4)
|
|
312
|
+
};
|
|
313
|
+
/**
|
|
314
|
+
* An additional name for the file.
|
|
315
|
+
*
|
|
316
|
+
*/
|
|
317
|
+
get id() {
|
|
318
|
+
return $.utils.getText(0, this);
|
|
319
|
+
}
|
|
320
|
+
set id(value) {
|
|
325
321
|
$.utils.setText(0, value, this);
|
|
326
322
|
}
|
|
323
|
+
/**
|
|
324
|
+
* The file exports.
|
|
325
|
+
*
|
|
326
|
+
*/
|
|
327
|
+
get name() {
|
|
328
|
+
return $.utils.getText(1, this);
|
|
329
|
+
}
|
|
330
|
+
set name(value) {
|
|
331
|
+
$.utils.setText(1, value, this);
|
|
332
|
+
}
|
|
333
|
+
_adoptExports(value) {
|
|
334
|
+
$.utils.adopt(value, $.utils.getPointer(2, this));
|
|
335
|
+
}
|
|
336
|
+
_disownExports() {
|
|
337
|
+
return $.utils.disown(this.exports);
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* The source map for the file.
|
|
341
|
+
*
|
|
342
|
+
*/
|
|
343
|
+
get exports() {
|
|
344
|
+
return $.utils.getList(2, $.TextList, this);
|
|
345
|
+
}
|
|
346
|
+
_hasExports() {
|
|
347
|
+
return !$.utils.isNull($.utils.getPointer(2, this));
|
|
348
|
+
}
|
|
349
|
+
_initExports(length) {
|
|
350
|
+
return $.utils.initList(2, $.TextList, length, this);
|
|
351
|
+
}
|
|
352
|
+
set exports(value) {
|
|
353
|
+
$.utils.copyFrom(value, $.utils.getPointer(2, this));
|
|
354
|
+
}
|
|
355
|
+
get map() {
|
|
356
|
+
return $.utils.getText(3, this);
|
|
357
|
+
}
|
|
358
|
+
set map(value) {
|
|
359
|
+
$.utils.setText(3, value, this);
|
|
360
|
+
}
|
|
361
|
+
toString() {
|
|
362
|
+
return "PrebuiltData_" + super.toString();
|
|
363
|
+
}
|
|
364
|
+
};
|
|
365
|
+
var AssetData = class extends $.Struct {
|
|
366
|
+
static {
|
|
367
|
+
__name(this, "AssetData");
|
|
368
|
+
}
|
|
369
|
+
static _capnp = {
|
|
370
|
+
displayName: "AssetData",
|
|
371
|
+
id: "da660c6c1fa4c830",
|
|
372
|
+
size: new $.ObjectSize(8, 3)
|
|
373
|
+
};
|
|
374
|
+
/**
|
|
375
|
+
* An additional name for the file.
|
|
376
|
+
*
|
|
377
|
+
*/
|
|
327
378
|
get id() {
|
|
379
|
+
return $.utils.getText(0, this);
|
|
380
|
+
}
|
|
381
|
+
set id(value) {
|
|
382
|
+
$.utils.setText(0, value, this);
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* Indicates whether the file needs a code reference.
|
|
386
|
+
*
|
|
387
|
+
*/
|
|
388
|
+
get name() {
|
|
328
389
|
return $.utils.getText(1, this);
|
|
329
390
|
}
|
|
391
|
+
set name(value) {
|
|
392
|
+
$.utils.setText(1, value, this);
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* The original file name before any transformations.
|
|
396
|
+
*
|
|
397
|
+
*/
|
|
398
|
+
get needsCodeReference() {
|
|
399
|
+
return $.utils.getBit(0, this);
|
|
400
|
+
}
|
|
401
|
+
set needsCodeReference(value) {
|
|
402
|
+
$.utils.setBit(0, value, this);
|
|
403
|
+
}
|
|
404
|
+
get originalFileName() {
|
|
405
|
+
return $.utils.getText(2, this);
|
|
406
|
+
}
|
|
407
|
+
set originalFileName(value) {
|
|
408
|
+
$.utils.setText(2, value, this);
|
|
409
|
+
}
|
|
410
|
+
toString() {
|
|
411
|
+
return "AssetData_" + super.toString();
|
|
412
|
+
}
|
|
413
|
+
};
|
|
414
|
+
var FileId = class extends $.Struct {
|
|
415
|
+
static {
|
|
416
|
+
__name(this, "FileId");
|
|
417
|
+
}
|
|
418
|
+
static _capnp = {
|
|
419
|
+
displayName: "FileId",
|
|
420
|
+
id: "990d6a471072f997",
|
|
421
|
+
size: new $.ObjectSize(0, 2)
|
|
422
|
+
};
|
|
423
|
+
/**
|
|
424
|
+
* A virtual (or actual) path to the file in the file system.
|
|
425
|
+
*
|
|
426
|
+
*/
|
|
427
|
+
get id() {
|
|
428
|
+
return $.utils.getText(0, this);
|
|
429
|
+
}
|
|
330
430
|
set id(value) {
|
|
431
|
+
$.utils.setText(0, value, this);
|
|
432
|
+
}
|
|
433
|
+
get path() {
|
|
434
|
+
return $.utils.getText(1, this);
|
|
435
|
+
}
|
|
436
|
+
set path(value) {
|
|
331
437
|
$.utils.setText(1, value, this);
|
|
332
438
|
}
|
|
333
439
|
toString() {
|
|
334
|
-
return "
|
|
440
|
+
return "FileId_" + super.toString();
|
|
335
441
|
}
|
|
336
442
|
};
|
|
337
443
|
var FileData = class extends $.Struct {
|
|
@@ -344,7 +450,7 @@ var FileData = class extends $.Struct {
|
|
|
344
450
|
size: new $.ObjectSize(0, 2)
|
|
345
451
|
};
|
|
346
452
|
/**
|
|
347
|
-
*
|
|
453
|
+
* A virtual (or actual) path to the file in the file system.
|
|
348
454
|
*
|
|
349
455
|
*/
|
|
350
456
|
get path() {
|
|
@@ -353,28 +459,31 @@ var FileData = class extends $.Struct {
|
|
|
353
459
|
set path(value) {
|
|
354
460
|
$.utils.setText(0, value, this);
|
|
355
461
|
}
|
|
356
|
-
get
|
|
462
|
+
get code() {
|
|
357
463
|
return $.utils.getText(1, this);
|
|
358
464
|
}
|
|
359
|
-
set
|
|
465
|
+
set code(value) {
|
|
360
466
|
$.utils.setText(1, value, this);
|
|
361
467
|
}
|
|
362
468
|
toString() {
|
|
363
469
|
return "FileData_" + super.toString();
|
|
364
470
|
}
|
|
365
471
|
};
|
|
366
|
-
var
|
|
472
|
+
var FileSystem = class _FileSystem extends $.Struct {
|
|
367
473
|
static {
|
|
368
|
-
__name(this, "
|
|
474
|
+
__name(this, "FileSystem");
|
|
369
475
|
}
|
|
370
476
|
static _capnp = {
|
|
371
|
-
displayName: "
|
|
372
|
-
id: "
|
|
373
|
-
size: new $.ObjectSize(0,
|
|
477
|
+
displayName: "FileSystem",
|
|
478
|
+
id: "ae0c23d43e56abcf",
|
|
479
|
+
size: new $.ObjectSize(0, 6)
|
|
374
480
|
};
|
|
375
481
|
static _Ids;
|
|
376
|
-
static _Metadata;
|
|
377
482
|
static _Files;
|
|
483
|
+
static _Metadata;
|
|
484
|
+
static _Assets;
|
|
485
|
+
static _Chunks;
|
|
486
|
+
static _Prebuilt;
|
|
378
487
|
_adoptIds(value) {
|
|
379
488
|
$.utils.adopt(value, $.utils.getPointer(0, this));
|
|
380
489
|
}
|
|
@@ -382,63 +491,120 @@ var FileSystemData = class _FileSystemData extends $.Struct {
|
|
|
382
491
|
return $.utils.disown(this.ids);
|
|
383
492
|
}
|
|
384
493
|
get ids() {
|
|
385
|
-
return $.utils.getList(0,
|
|
494
|
+
return $.utils.getList(0, _FileSystem._Ids, this);
|
|
386
495
|
}
|
|
387
496
|
_hasIds() {
|
|
388
497
|
return !$.utils.isNull($.utils.getPointer(0, this));
|
|
389
498
|
}
|
|
390
499
|
_initIds(length) {
|
|
391
|
-
return $.utils.initList(0,
|
|
500
|
+
return $.utils.initList(0, _FileSystem._Ids, length, this);
|
|
392
501
|
}
|
|
393
502
|
set ids(value) {
|
|
394
503
|
$.utils.copyFrom(value, $.utils.getPointer(0, this));
|
|
395
504
|
}
|
|
396
|
-
|
|
505
|
+
_adoptFiles(value) {
|
|
397
506
|
$.utils.adopt(value, $.utils.getPointer(1, this));
|
|
398
507
|
}
|
|
399
|
-
|
|
400
|
-
return $.utils.disown(this.
|
|
508
|
+
_disownFiles() {
|
|
509
|
+
return $.utils.disown(this.files);
|
|
401
510
|
}
|
|
402
|
-
get
|
|
403
|
-
return $.utils.getList(1,
|
|
511
|
+
get files() {
|
|
512
|
+
return $.utils.getList(1, _FileSystem._Files, this);
|
|
404
513
|
}
|
|
405
|
-
|
|
514
|
+
_hasFiles() {
|
|
406
515
|
return !$.utils.isNull($.utils.getPointer(1, this));
|
|
407
516
|
}
|
|
408
|
-
|
|
409
|
-
return $.utils.initList(1,
|
|
517
|
+
_initFiles(length) {
|
|
518
|
+
return $.utils.initList(1, _FileSystem._Files, length, this);
|
|
410
519
|
}
|
|
411
|
-
set
|
|
520
|
+
set files(value) {
|
|
412
521
|
$.utils.copyFrom(value, $.utils.getPointer(1, this));
|
|
413
522
|
}
|
|
414
|
-
|
|
523
|
+
_adoptMetadata(value) {
|
|
415
524
|
$.utils.adopt(value, $.utils.getPointer(2, this));
|
|
416
525
|
}
|
|
417
|
-
|
|
418
|
-
return $.utils.disown(this.
|
|
526
|
+
_disownMetadata() {
|
|
527
|
+
return $.utils.disown(this.metadata);
|
|
419
528
|
}
|
|
420
|
-
get
|
|
421
|
-
return $.utils.getList(2,
|
|
529
|
+
get metadata() {
|
|
530
|
+
return $.utils.getList(2, _FileSystem._Metadata, this);
|
|
422
531
|
}
|
|
423
|
-
|
|
532
|
+
_hasMetadata() {
|
|
424
533
|
return !$.utils.isNull($.utils.getPointer(2, this));
|
|
425
534
|
}
|
|
426
|
-
|
|
427
|
-
return $.utils.initList(2,
|
|
535
|
+
_initMetadata(length) {
|
|
536
|
+
return $.utils.initList(2, _FileSystem._Metadata, length, this);
|
|
428
537
|
}
|
|
429
|
-
set
|
|
538
|
+
set metadata(value) {
|
|
430
539
|
$.utils.copyFrom(value, $.utils.getPointer(2, this));
|
|
431
540
|
}
|
|
541
|
+
_adoptAssets(value) {
|
|
542
|
+
$.utils.adopt(value, $.utils.getPointer(3, this));
|
|
543
|
+
}
|
|
544
|
+
_disownAssets() {
|
|
545
|
+
return $.utils.disown(this.assets);
|
|
546
|
+
}
|
|
547
|
+
get assets() {
|
|
548
|
+
return $.utils.getList(3, _FileSystem._Assets, this);
|
|
549
|
+
}
|
|
550
|
+
_hasAssets() {
|
|
551
|
+
return !$.utils.isNull($.utils.getPointer(3, this));
|
|
552
|
+
}
|
|
553
|
+
_initAssets(length) {
|
|
554
|
+
return $.utils.initList(3, _FileSystem._Assets, length, this);
|
|
555
|
+
}
|
|
556
|
+
set assets(value) {
|
|
557
|
+
$.utils.copyFrom(value, $.utils.getPointer(3, this));
|
|
558
|
+
}
|
|
559
|
+
_adoptChunks(value) {
|
|
560
|
+
$.utils.adopt(value, $.utils.getPointer(4, this));
|
|
561
|
+
}
|
|
562
|
+
_disownChunks() {
|
|
563
|
+
return $.utils.disown(this.chunks);
|
|
564
|
+
}
|
|
565
|
+
get chunks() {
|
|
566
|
+
return $.utils.getList(4, _FileSystem._Chunks, this);
|
|
567
|
+
}
|
|
568
|
+
_hasChunks() {
|
|
569
|
+
return !$.utils.isNull($.utils.getPointer(4, this));
|
|
570
|
+
}
|
|
571
|
+
_initChunks(length) {
|
|
572
|
+
return $.utils.initList(4, _FileSystem._Chunks, length, this);
|
|
573
|
+
}
|
|
574
|
+
set chunks(value) {
|
|
575
|
+
$.utils.copyFrom(value, $.utils.getPointer(4, this));
|
|
576
|
+
}
|
|
577
|
+
_adoptPrebuilt(value) {
|
|
578
|
+
$.utils.adopt(value, $.utils.getPointer(5, this));
|
|
579
|
+
}
|
|
580
|
+
_disownPrebuilt() {
|
|
581
|
+
return $.utils.disown(this.prebuilt);
|
|
582
|
+
}
|
|
583
|
+
get prebuilt() {
|
|
584
|
+
return $.utils.getList(5, _FileSystem._Prebuilt, this);
|
|
585
|
+
}
|
|
586
|
+
_hasPrebuilt() {
|
|
587
|
+
return !$.utils.isNull($.utils.getPointer(5, this));
|
|
588
|
+
}
|
|
589
|
+
_initPrebuilt(length) {
|
|
590
|
+
return $.utils.initList(5, _FileSystem._Prebuilt, length, this);
|
|
591
|
+
}
|
|
592
|
+
set prebuilt(value) {
|
|
593
|
+
$.utils.copyFrom(value, $.utils.getPointer(5, this));
|
|
594
|
+
}
|
|
432
595
|
toString() {
|
|
433
|
-
return "
|
|
596
|
+
return "FileSystem_" + super.toString();
|
|
434
597
|
}
|
|
435
598
|
};
|
|
436
599
|
FileMetadata._Properties = $.CompositeList(FileMetadata_KeyValuePair);
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
600
|
+
FileSystem._Ids = $.CompositeList(FileId);
|
|
601
|
+
FileSystem._Files = $.CompositeList(FileData);
|
|
602
|
+
FileSystem._Metadata = $.CompositeList(FileMetadata);
|
|
603
|
+
FileSystem._Assets = $.CompositeList(AssetData);
|
|
604
|
+
FileSystem._Chunks = $.CompositeList(ChunkData);
|
|
605
|
+
FileSystem._Prebuilt = $.CompositeList(PrebuiltData);
|
|
440
606
|
|
|
441
|
-
// src/types/
|
|
607
|
+
// src/types/fs.ts
|
|
442
608
|
var __VFS_PATCH__ = "__VFS_PATCH__";
|
|
443
609
|
var __VFS_REVERT__ = "__VFS_REVERT__";
|
|
444
610
|
function isBufferEncoding(options) {
|
|
@@ -453,10 +619,10 @@ function isNodeWriteFileOptions(options) {
|
|
|
453
619
|
return !isUndefined(options) && (isBufferEncoding(options) || !isPowerlinesWriteFileOptions(options));
|
|
454
620
|
}
|
|
455
621
|
__name(isNodeWriteFileOptions, "isNodeWriteFileOptions");
|
|
456
|
-
function
|
|
457
|
-
return !!(isSetObject(
|
|
622
|
+
function isVirtualFileData(obj) {
|
|
623
|
+
return !!(isSetObject(obj) && "code" in obj && obj.code);
|
|
458
624
|
}
|
|
459
|
-
__name(
|
|
625
|
+
__name(isVirtualFileData, "isVirtualFileData");
|
|
460
626
|
var FILE_PREFIX = "file://";
|
|
461
627
|
function toFilePath(pathOrUrl) {
|
|
462
628
|
if (!pathOrUrl) {
|
|
@@ -600,13 +766,13 @@ var UnifiedFS = class _UnifiedFS extends Union {
|
|
|
600
766
|
/**
|
|
601
767
|
* The physical file system.
|
|
602
768
|
*/
|
|
603
|
-
#physicalFS = cloneFS(
|
|
769
|
+
#physicalFS = cloneFS(_fs);
|
|
604
770
|
/**
|
|
605
771
|
* The context of the unified file system.
|
|
606
772
|
*/
|
|
607
773
|
#context;
|
|
608
|
-
static create(context,
|
|
609
|
-
let result = new _UnifiedFS(context,
|
|
774
|
+
static create(context, fs2) {
|
|
775
|
+
let result = new _UnifiedFS(context, fs2);
|
|
610
776
|
result = result.use(result.#physicalFS);
|
|
611
777
|
if (result.#context.config.output.mode !== "fs") {
|
|
612
778
|
result = result.use(result.#virtualFS);
|
|
@@ -629,9 +795,9 @@ var UnifiedFS = class _UnifiedFS extends Union {
|
|
|
629
795
|
* Creates a new instance of the VirtualFileSystem.
|
|
630
796
|
*
|
|
631
797
|
* @param context - The context of the virtual file system, typically containing options and logging functions.
|
|
632
|
-
* @param
|
|
798
|
+
* @param fs - A buffer containing the serialized virtual file system data.
|
|
633
799
|
*/
|
|
634
|
-
constructor(context,
|
|
800
|
+
constructor(context, fs2) {
|
|
635
801
|
super();
|
|
636
802
|
this.#context = context;
|
|
637
803
|
if (!this.#physicalFS.existsSync(this.#context.dataPath)) {
|
|
@@ -650,8 +816,8 @@ var UnifiedFS = class _UnifiedFS extends Union {
|
|
|
650
816
|
});
|
|
651
817
|
}
|
|
652
818
|
if (this.#context.config.output.mode !== "fs") {
|
|
653
|
-
this.#virtualFS = Volume.fromJSON(
|
|
654
|
-
ret[file.path] = file.
|
|
819
|
+
this.#virtualFS = Volume.fromJSON(fs2._hasFiles() && fs2.files.length > 0 ? fs2.files.values().reduce((ret, file) => {
|
|
820
|
+
ret[file.path] = file.code;
|
|
655
821
|
return ret;
|
|
656
822
|
}, {}) : {});
|
|
657
823
|
if (!this.#virtualFS.existsSync(this.#context.artifactsPath)) {
|
|
@@ -996,10 +1162,10 @@ var VirtualFileSystem = class _VirtualFileSystem {
|
|
|
996
1162
|
if (!context.config.skipCache && existsSync(joinPaths$1(context.cachePath, "fs.bin"))) {
|
|
997
1163
|
const buffer = await readFileBuffer(joinPaths$1(context.cachePath, "fs.bin"));
|
|
998
1164
|
const message2 = new $.Message(buffer, false);
|
|
999
|
-
return new _VirtualFileSystem(context, message2.getRoot(
|
|
1165
|
+
return new _VirtualFileSystem(context, message2.getRoot(FileSystem));
|
|
1000
1166
|
}
|
|
1001
1167
|
const message = new $.Message();
|
|
1002
|
-
return new _VirtualFileSystem(context, message.initRoot(
|
|
1168
|
+
return new _VirtualFileSystem(context, message.initRoot(FileSystem));
|
|
1003
1169
|
}
|
|
1004
1170
|
/**
|
|
1005
1171
|
* Synchronously creates a virtual file system (VFS) that is backed up to a Cap'n Proto message buffer.
|
|
@@ -1011,10 +1177,10 @@ var VirtualFileSystem = class _VirtualFileSystem {
|
|
|
1011
1177
|
if (!context.config.skipCache && existsSync(joinPaths$1(context.cachePath, "fs.bin"))) {
|
|
1012
1178
|
const buffer = readFileBufferSync(joinPaths$1(context.cachePath, "fs.bin"));
|
|
1013
1179
|
const message2 = new $.Message(buffer, false);
|
|
1014
|
-
return new _VirtualFileSystem(context, message2.getRoot(
|
|
1180
|
+
return new _VirtualFileSystem(context, message2.getRoot(FileSystem));
|
|
1015
1181
|
}
|
|
1016
1182
|
const message = new $.Message();
|
|
1017
|
-
return new _VirtualFileSystem(context, message.initRoot(
|
|
1183
|
+
return new _VirtualFileSystem(context, message.initRoot(FileSystem));
|
|
1018
1184
|
}
|
|
1019
1185
|
/**
|
|
1020
1186
|
* A map of file ids to their metadata.
|
|
@@ -1038,19 +1204,20 @@ var VirtualFileSystem = class _VirtualFileSystem {
|
|
|
1038
1204
|
* Creates a new instance of the {@link VirtualFileSystem}.
|
|
1039
1205
|
*
|
|
1040
1206
|
* @param context - The context of the virtual file system, typically containing options and logging functions.
|
|
1041
|
-
* @param
|
|
1207
|
+
* @param fs - A buffer containing the serialized virtual file system data.
|
|
1042
1208
|
*/
|
|
1043
|
-
constructor(context,
|
|
1209
|
+
constructor(context, fs2) {
|
|
1044
1210
|
this.#context = context;
|
|
1045
|
-
this.#unifiedFS = UnifiedFS.create(context,
|
|
1211
|
+
this.#unifiedFS = UnifiedFS.create(context, fs2);
|
|
1046
1212
|
this.#metadata = {};
|
|
1047
|
-
if (
|
|
1048
|
-
this.#metadata =
|
|
1049
|
-
ret[
|
|
1050
|
-
id:
|
|
1051
|
-
|
|
1052
|
-
mode:
|
|
1053
|
-
|
|
1213
|
+
if (fs2._hasMetadata()) {
|
|
1214
|
+
this.#metadata = fs2.metadata.values().reduce((ret, metadata) => {
|
|
1215
|
+
ret[metadata.id] = {
|
|
1216
|
+
id: metadata.id,
|
|
1217
|
+
type: metadata.type,
|
|
1218
|
+
mode: metadata.mode,
|
|
1219
|
+
timestamp: metadata.timestamp || Date.now(),
|
|
1220
|
+
properties: metadata._hasProperties() ? metadata.properties.values().reduce((ret2, item) => {
|
|
1054
1221
|
ret2[item.key] = item.value;
|
|
1055
1222
|
return ret2;
|
|
1056
1223
|
}, {}) : {}
|
|
@@ -1060,14 +1227,13 @@ var VirtualFileSystem = class _VirtualFileSystem {
|
|
|
1060
1227
|
}
|
|
1061
1228
|
this.#ids = {};
|
|
1062
1229
|
this.#paths = {};
|
|
1063
|
-
if (
|
|
1064
|
-
this.#ids =
|
|
1065
|
-
ret[
|
|
1066
|
-
ret[data2.path] ??= data2.path;
|
|
1230
|
+
if (fs2._hasIds()) {
|
|
1231
|
+
this.#ids = fs2.ids.values().reduce((ret, identifier) => {
|
|
1232
|
+
ret[identifier.path] ??= identifier.id;
|
|
1067
1233
|
return ret;
|
|
1068
1234
|
}, {});
|
|
1069
|
-
this.#paths =
|
|
1070
|
-
ret[
|
|
1235
|
+
this.#paths = fs2.ids.values().reduce((ret, identifier) => {
|
|
1236
|
+
ret[identifier.id] ??= identifier.path;
|
|
1071
1237
|
return ret;
|
|
1072
1238
|
}, {});
|
|
1073
1239
|
}
|
|
@@ -1086,7 +1252,7 @@ var VirtualFileSystem = class _VirtualFileSystem {
|
|
|
1086
1252
|
}
|
|
1087
1253
|
const resolvedPath = this.resolve(pathOrId, {
|
|
1088
1254
|
...options,
|
|
1089
|
-
|
|
1255
|
+
pathType: "file"
|
|
1090
1256
|
});
|
|
1091
1257
|
if (!resolvedPath) {
|
|
1092
1258
|
return false;
|
|
@@ -1106,7 +1272,7 @@ var VirtualFileSystem = class _VirtualFileSystem {
|
|
|
1106
1272
|
}
|
|
1107
1273
|
const resolvedPath = this.resolve(pathOrId, {
|
|
1108
1274
|
...options,
|
|
1109
|
-
|
|
1275
|
+
pathType: "file"
|
|
1110
1276
|
});
|
|
1111
1277
|
if (!resolvedPath) {
|
|
1112
1278
|
return false;
|
|
@@ -1279,7 +1445,7 @@ var VirtualFileSystem = class _VirtualFileSystem {
|
|
|
1279
1445
|
const normalized = this.formatPath(pattern);
|
|
1280
1446
|
if (!/[*?[\]{}]/.test(normalized) && !normalized.includes("**")) {
|
|
1281
1447
|
const resolved = this.resolve(normalized, {
|
|
1282
|
-
|
|
1448
|
+
pathType: "file"
|
|
1283
1449
|
});
|
|
1284
1450
|
if (resolved && !results.includes(resolved)) {
|
|
1285
1451
|
results.push(resolved);
|
|
@@ -1314,7 +1480,7 @@ var VirtualFileSystem = class _VirtualFileSystem {
|
|
|
1314
1480
|
} else if (stats.isFile()) {
|
|
1315
1481
|
if (this.#buildRegex(absPattern).test(full)) {
|
|
1316
1482
|
const resolved = this.resolve(full, {
|
|
1317
|
-
|
|
1483
|
+
pathType: "file"
|
|
1318
1484
|
});
|
|
1319
1485
|
if (resolved && !results.includes(resolved)) {
|
|
1320
1486
|
results.push(resolved);
|
|
@@ -1338,7 +1504,7 @@ var VirtualFileSystem = class _VirtualFileSystem {
|
|
|
1338
1504
|
const normalized = this.formatPath(pattern);
|
|
1339
1505
|
if (!/[*?[\]{}]/.test(normalized) && !normalized.includes("**")) {
|
|
1340
1506
|
const resolved = this.resolve(normalized, {
|
|
1341
|
-
|
|
1507
|
+
pathType: "file"
|
|
1342
1508
|
});
|
|
1343
1509
|
if (resolved && !results.includes(resolved)) {
|
|
1344
1510
|
results.push(resolved);
|
|
@@ -1373,7 +1539,7 @@ var VirtualFileSystem = class _VirtualFileSystem {
|
|
|
1373
1539
|
} else if (stats.isFile()) {
|
|
1374
1540
|
if (this.#buildRegex(absPattern).test(full)) {
|
|
1375
1541
|
const resolved = this.resolve(full, {
|
|
1376
|
-
|
|
1542
|
+
pathType: "file"
|
|
1377
1543
|
});
|
|
1378
1544
|
if (resolved && !results.includes(resolved)) {
|
|
1379
1545
|
results.push(resolved);
|
|
@@ -1448,7 +1614,7 @@ var VirtualFileSystem = class _VirtualFileSystem {
|
|
|
1448
1614
|
return void 0;
|
|
1449
1615
|
}
|
|
1450
1616
|
const filePath = this.resolve(toFilePath(pathOrId), {
|
|
1451
|
-
|
|
1617
|
+
pathType: "file"
|
|
1452
1618
|
});
|
|
1453
1619
|
if (filePath) {
|
|
1454
1620
|
let result;
|
|
@@ -1473,7 +1639,7 @@ var VirtualFileSystem = class _VirtualFileSystem {
|
|
|
1473
1639
|
return void 0;
|
|
1474
1640
|
}
|
|
1475
1641
|
const filePath = this.resolve(toFilePath(pathOrId), {
|
|
1476
|
-
|
|
1642
|
+
pathType: "file"
|
|
1477
1643
|
});
|
|
1478
1644
|
if (filePath) {
|
|
1479
1645
|
const result = this.#unifiedFS.resolveFS(filePath).readFileSync(filePath, options);
|
|
@@ -1495,7 +1661,7 @@ var VirtualFileSystem = class _VirtualFileSystem {
|
|
|
1495
1661
|
if (!this.isDirectory(findFilePath(formattedPath))) {
|
|
1496
1662
|
await this.mkdir(findFilePath(formattedPath), isPowerlinesWriteFileOptions(options) ? options : void 0);
|
|
1497
1663
|
}
|
|
1498
|
-
let code =
|
|
1664
|
+
let code = isVirtualFileData(data) ? data.code : data;
|
|
1499
1665
|
if ((!isPowerlinesWriteFileOptions(options) || !options.skipFormat) && isSetString(code)) {
|
|
1500
1666
|
const resolvedConfig = await resolveConfig(formattedPath);
|
|
1501
1667
|
if (resolvedConfig) {
|
|
@@ -1510,7 +1676,8 @@ var VirtualFileSystem = class _VirtualFileSystem {
|
|
|
1510
1676
|
this.metadata[formattedPath] = {
|
|
1511
1677
|
mode: outputMode,
|
|
1512
1678
|
variant: "normal",
|
|
1513
|
-
|
|
1679
|
+
timestamp: Date.now(),
|
|
1680
|
+
...isVirtualFileData(data) ? data : {}
|
|
1514
1681
|
};
|
|
1515
1682
|
this.#clearResolverCache(formattedPath);
|
|
1516
1683
|
const ifs = this.#unifiedFS.resolveFS(formattedPath, isPowerlinesWriteFileOptions(options) ? options : void 0);
|
|
@@ -1531,13 +1698,14 @@ var VirtualFileSystem = class _VirtualFileSystem {
|
|
|
1531
1698
|
if (!this.isDirectory(findFilePath(formattedPath))) {
|
|
1532
1699
|
this.mkdirSync(findFilePath(formattedPath), isPowerlinesWriteFileOptions(options) ? options : void 0);
|
|
1533
1700
|
}
|
|
1534
|
-
const code =
|
|
1701
|
+
const code = isVirtualFileData(data) ? data.code : data;
|
|
1535
1702
|
const outputMode = this.#unifiedFS.resolveMode(formattedPath, isPowerlinesWriteFileOptions(options) ? options : void 0);
|
|
1536
1703
|
this.#log(LogLevelLabel.TRACE, `Writing ${formattedPath} file to the ${outputMode === "fs" ? "" : "virtual "}file system (size: ${prettyBytes(new Blob(toArray(code)).size)})`);
|
|
1537
1704
|
this.metadata[formattedPath] = {
|
|
1538
1705
|
mode: outputMode,
|
|
1539
1706
|
variant: "normal",
|
|
1540
|
-
|
|
1707
|
+
timestamp: Date.now(),
|
|
1708
|
+
...isVirtualFileData(data) ? data : {}
|
|
1541
1709
|
};
|
|
1542
1710
|
this.#clearResolverCache(formattedPath);
|
|
1543
1711
|
const writeStream = this.#unifiedFS.resolveFS(formattedPath, isPowerlinesWriteFileOptions(options) ? options : void 0).createWriteStream(formattedPath);
|
|
@@ -1650,7 +1818,7 @@ var VirtualFileSystem = class _VirtualFileSystem {
|
|
|
1650
1818
|
*/
|
|
1651
1819
|
resolve(pathOrId, options = {}) {
|
|
1652
1820
|
const formattedPathOrId = toFilePath(pathOrId);
|
|
1653
|
-
const resolverKey = `${formattedPathOrId}${options.withExtension ? "-ext" : ""}${options.paths ? `-${murmurhash(options.paths)}` : ""}${options.
|
|
1821
|
+
const resolverKey = `${formattedPathOrId}${options.withExtension ? "-ext" : ""}${options.paths ? `-${murmurhash(options.paths)}` : ""}${options.pathType ? `-${options.pathType}` : ""}`;
|
|
1654
1822
|
if (this.#cachedResolver.has(resolverKey)) {
|
|
1655
1823
|
return this.#cachedResolver.get(resolverKey);
|
|
1656
1824
|
}
|
|
@@ -1691,26 +1859,28 @@ var VirtualFileSystem = class _VirtualFileSystem {
|
|
|
1691
1859
|
this.#log(LogLevelLabel.DEBUG, "Disposing virtual file system...");
|
|
1692
1860
|
await this.unlink(joinPaths$1(this.#context.cachePath, "fs.bin"));
|
|
1693
1861
|
const message = new $.Message();
|
|
1694
|
-
const
|
|
1862
|
+
const fs2 = message.initRoot(FileSystem);
|
|
1695
1863
|
const virtualFS = this.#unifiedFS.toJSON();
|
|
1696
|
-
const
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1864
|
+
const virtualFiles = Object.entries(virtualFS).filter(([_, code]) => code);
|
|
1865
|
+
const files = fs2._initFiles(virtualFiles.length);
|
|
1866
|
+
virtualFiles.forEach(([path, code], index) => {
|
|
1867
|
+
const fd = files.get(index);
|
|
1868
|
+
fd.path = path;
|
|
1869
|
+
fd.code = code;
|
|
1701
1870
|
});
|
|
1702
|
-
const ids =
|
|
1871
|
+
const ids = fs2._initIds(Object.keys(this.ids).length);
|
|
1703
1872
|
Object.entries(this.ids).forEach(([id, path], index) => {
|
|
1704
1873
|
const fileId = ids.get(index);
|
|
1705
1874
|
fileId.id = id;
|
|
1706
1875
|
fileId.path = path;
|
|
1707
1876
|
});
|
|
1708
|
-
const metadata =
|
|
1877
|
+
const metadata = fs2._initMetadata(Object.keys(this.metadata).length);
|
|
1709
1878
|
Object.entries(this.metadata).forEach(([id, value], index) => {
|
|
1710
1879
|
const fileMetadata = metadata.get(index);
|
|
1711
1880
|
fileMetadata.id = id;
|
|
1712
1881
|
fileMetadata.mode = value.mode;
|
|
1713
|
-
fileMetadata.
|
|
1882
|
+
fileMetadata.type = value.type;
|
|
1883
|
+
fileMetadata.timestamp = value.timestamp ?? BigInt(Date.now());
|
|
1714
1884
|
if (value.properties) {
|
|
1715
1885
|
const props = fileMetadata._initProperties(Object.keys(value.properties).length);
|
|
1716
1886
|
Object.entries(value.properties).forEach(([key, val], propIndex) => {
|
|
@@ -1728,7 +1898,7 @@ var VirtualFileSystem = class _VirtualFileSystem {
|
|
|
1728
1898
|
*/
|
|
1729
1899
|
[__VFS_PATCH__]() {
|
|
1730
1900
|
if (!this.#isPatched && this.#context.config.output.mode !== "fs") {
|
|
1731
|
-
this.#revert = patchFS(
|
|
1901
|
+
this.#revert = patchFS(_fs, this);
|
|
1732
1902
|
this.#isPatched = true;
|
|
1733
1903
|
}
|
|
1734
1904
|
}
|
|
@@ -1749,101 +1919,18 @@ var VirtualFileSystem = class _VirtualFileSystem {
|
|
|
1749
1919
|
}
|
|
1750
1920
|
};
|
|
1751
1921
|
|
|
1752
|
-
// src/
|
|
1753
|
-
var SUPPORTED_COMMANDS = [
|
|
1754
|
-
"new",
|
|
1755
|
-
"clean",
|
|
1756
|
-
"prepare",
|
|
1757
|
-
"lint",
|
|
1758
|
-
"test",
|
|
1759
|
-
"build",
|
|
1760
|
-
"docs",
|
|
1761
|
-
"deploy",
|
|
1762
|
-
"finalize"
|
|
1763
|
-
];
|
|
1764
|
-
|
|
1765
|
-
// src/plugin-utils/helpers.ts
|
|
1766
|
-
function isPlugin(value) {
|
|
1767
|
-
return isSetObject(value) && "name" in value && isSetString(value.name) && (isUndefined(value.applyToEnvironment) || "applyToEnvironment" in value && isFunction(value.applyToEnvironment)) && (isUndefined(value.dedupe) || "dedupe" in value && isFunction(value.dedupe)) && (isUndefined(value.dependsOn) || "dependsOn" in value && Array.isArray(value.dependsOn) && value.dependsOn.every(isPluginConfig)) && SUPPORTED_COMMANDS.every((command) => isUndefined(value[command]) || command in value && (isFunction(value[command]) || isSetObject(value[command]) && "handler" in value[command] && isFunction(value[command].handler)));
|
|
1768
|
-
}
|
|
1769
|
-
__name(isPlugin, "isPlugin");
|
|
1770
|
-
function isPluginConfigObject(value) {
|
|
1771
|
-
return isSetObject(value) && "plugin" in value && ((isSetString(value.plugin) || isFunction(value.plugin)) && "options" in value && isSetObject(value.options) || isPlugin(value.plugin));
|
|
1772
|
-
}
|
|
1773
|
-
__name(isPluginConfigObject, "isPluginConfigObject");
|
|
1774
|
-
function isPluginConfigTuple(value) {
|
|
1775
|
-
return Array.isArray(value) && (value.length === 1 || value.length === 2) && ((isSetString(value[0]) || isFunction(value[0])) && value.length > 1 && isSetObject(value[1]) || isPlugin(value[0]));
|
|
1776
|
-
}
|
|
1777
|
-
__name(isPluginConfigTuple, "isPluginConfigTuple");
|
|
1778
|
-
function isPluginConfig(value) {
|
|
1779
|
-
return isSetString(value) || isFunction(value) || isPlugin(value) || isPluginConfigObject(value) || isPluginConfigTuple(value);
|
|
1780
|
-
}
|
|
1781
|
-
__name(isPluginConfig, "isPluginConfig");
|
|
1782
|
-
function isPluginHookFunction(value) {
|
|
1783
|
-
return isFunction(value) || isSetObject(value) && "handler" in value && isFunction(value.handler);
|
|
1784
|
-
}
|
|
1785
|
-
__name(isPluginHookFunction, "isPluginHookFunction");
|
|
1786
|
-
function isPluginHookObject(value) {
|
|
1787
|
-
return isSetObject(value) && "handler" in value && isFunction(value.handler);
|
|
1788
|
-
}
|
|
1789
|
-
__name(isPluginHookObject, "isPluginHookObject");
|
|
1790
|
-
function isPluginHook(value) {
|
|
1791
|
-
return isPluginHookFunction(value) || isPluginHookObject(value);
|
|
1792
|
-
}
|
|
1793
|
-
__name(isPluginHook, "isPluginHook");
|
|
1794
|
-
function getHookHandler(pluginHook) {
|
|
1795
|
-
return isFunction(pluginHook) ? pluginHook : pluginHook.handler;
|
|
1796
|
-
}
|
|
1797
|
-
__name(getHookHandler, "getHookHandler");
|
|
1798
|
-
function isHookExternal(hook) {
|
|
1799
|
-
return hook.startsWith("vite:") || hook.startsWith("esbuild:") || hook.startsWith("rolldown:") || hook.startsWith("rollup:") || hook.startsWith("webpack:") || hook.startsWith("rspack:") || hook.startsWith("farm:");
|
|
1800
|
-
}
|
|
1801
|
-
__name(isHookExternal, "isHookExternal");
|
|
1802
|
-
function checkDedupe(plugin, plugins) {
|
|
1803
|
-
return plugin.dedupe === false || plugins.some((p) => p.dedupe !== false && (isFunction(p.dedupe) && p.dedupe(plugin) || p.name === plugin.name));
|
|
1804
|
-
}
|
|
1805
|
-
__name(checkDedupe, "checkDedupe");
|
|
1806
|
-
function addPluginHook(context, plugin, pluginHook, hooksList) {
|
|
1807
|
-
if (!checkDedupe(plugin, hooksList.map((hook) => hook.plugin))) {
|
|
1808
|
-
hooksList.push(isFunction(pluginHook) ? {
|
|
1809
|
-
plugin,
|
|
1810
|
-
handler: getHookHandler(pluginHook).bind(context)
|
|
1811
|
-
} : {
|
|
1812
|
-
plugin,
|
|
1813
|
-
...pluginHook,
|
|
1814
|
-
handler: getHookHandler(pluginHook).bind(context)
|
|
1815
|
-
});
|
|
1816
|
-
}
|
|
1817
|
-
}
|
|
1818
|
-
__name(addPluginHook, "addPluginHook");
|
|
1819
|
-
function resolveOptions(options) {
|
|
1820
|
-
return defu2(options, {
|
|
1821
|
-
interopDefault: true,
|
|
1822
|
-
fsCache: options.mode !== "development" ? joinPaths$1(options.cacheDir, "jiti") : false,
|
|
1823
|
-
moduleCache: options.mode !== "development"
|
|
1824
|
-
});
|
|
1825
|
-
}
|
|
1826
|
-
__name(resolveOptions, "resolveOptions");
|
|
1827
|
-
function createPluginResolver(options) {
|
|
1828
|
-
return createJiti(joinPaths$1(options.workspaceRoot, options.projectRoot), resolveOptions({
|
|
1829
|
-
...options
|
|
1830
|
-
}));
|
|
1831
|
-
}
|
|
1832
|
-
__name(createPluginResolver, "createPluginResolver");
|
|
1833
|
-
function createResolver(options) {
|
|
1834
|
-
const baseResolver = createJiti(joinPaths$1(options.workspaceRoot, options.projectRoot), resolveOptions(options));
|
|
1835
|
-
baseResolver.plugin = createPluginResolver(options);
|
|
1836
|
-
return baseResolver;
|
|
1837
|
-
}
|
|
1838
|
-
__name(createResolver, "createResolver");
|
|
1839
|
-
|
|
1840
|
-
// src/internal/contexts/context.ts
|
|
1922
|
+
// src/lib/contexts/context.ts
|
|
1841
1923
|
var configCache = /* @__PURE__ */ new WeakMap();
|
|
1842
|
-
var parseCache = /* @__PURE__ */ new WeakMap();
|
|
1843
1924
|
var PowerlinesContext = class _PowerlinesContext {
|
|
1844
1925
|
static {
|
|
1845
1926
|
__name(this, "PowerlinesContext");
|
|
1846
1927
|
}
|
|
1928
|
+
/**
|
|
1929
|
+
* Internal reference to the API instance
|
|
1930
|
+
*
|
|
1931
|
+
* @internal
|
|
1932
|
+
*/
|
|
1933
|
+
#api;
|
|
1847
1934
|
#workspaceConfig;
|
|
1848
1935
|
#checksum = null;
|
|
1849
1936
|
#buildId = uuid();
|
|
@@ -1923,6 +2010,16 @@ var PowerlinesContext = class _PowerlinesContext {
|
|
|
1923
2010
|
*/
|
|
1924
2011
|
resolver;
|
|
1925
2012
|
/**
|
|
2013
|
+
* Internal context fields and methods
|
|
2014
|
+
*
|
|
2015
|
+
* @internal
|
|
2016
|
+
*/
|
|
2017
|
+
get $$internal() {
|
|
2018
|
+
return {
|
|
2019
|
+
api: this.#api
|
|
2020
|
+
};
|
|
2021
|
+
}
|
|
2022
|
+
/**
|
|
1926
2023
|
* The resolved entry type definitions for the project
|
|
1927
2024
|
*/
|
|
1928
2025
|
get entry() {
|
|
@@ -2065,13 +2162,13 @@ var PowerlinesContext = class _PowerlinesContext {
|
|
|
2065
2162
|
* The builtin module id that exist in the Powerlines virtual file system
|
|
2066
2163
|
*/
|
|
2067
2164
|
get builtins() {
|
|
2068
|
-
return Object.values(this.fs.metadata).filter((meta) => meta && meta.
|
|
2165
|
+
return Object.values(this.fs.metadata).filter((meta) => meta && meta.type === "builtin").map((meta) => meta?.id).filter(Boolean);
|
|
2069
2166
|
}
|
|
2070
2167
|
/**
|
|
2071
2168
|
* Get the builtin virtual files that exist in the Powerlines virtual file system
|
|
2072
2169
|
*/
|
|
2073
2170
|
async getBuiltins() {
|
|
2074
|
-
return Promise.all(Object.entries(this.fs.metadata).filter(([, meta]) => meta && meta.
|
|
2171
|
+
return Promise.all(Object.entries(this.fs.metadata).filter(([, meta]) => meta && meta.type === "builtin").map(async ([path, meta]) => {
|
|
2075
2172
|
const code = await this.fs.readFile(path);
|
|
2076
2173
|
return {
|
|
2077
2174
|
...meta,
|
|
@@ -2087,10 +2184,10 @@ var PowerlinesContext = class _PowerlinesContext {
|
|
|
2087
2184
|
* @param path - A path to write the entry file to
|
|
2088
2185
|
* @param options - Optional write file options
|
|
2089
2186
|
*/
|
|
2090
|
-
async
|
|
2187
|
+
async emitEntry(code, path, options = {}) {
|
|
2091
2188
|
return this.fs.writeFile(isAbsolute(path) ? path : appendPath(path, this.entryPath), {
|
|
2092
2189
|
code,
|
|
2093
|
-
|
|
2190
|
+
type: "entry"
|
|
2094
2191
|
}, defu2(options, {
|
|
2095
2192
|
mode: this.config.output.mode
|
|
2096
2193
|
}));
|
|
@@ -2103,51 +2200,16 @@ var PowerlinesContext = class _PowerlinesContext {
|
|
|
2103
2200
|
* @param path - An optional path to write the builtin file to
|
|
2104
2201
|
* @param options - Optional write file options
|
|
2105
2202
|
*/
|
|
2106
|
-
async
|
|
2203
|
+
async emitBuiltin(code, id, path, options = {}) {
|
|
2107
2204
|
return this.fs.writeFile(path ? isAbsolute(path) ? path : joinPaths(this.builtinsPath, path) : appendPath(id, this.builtinsPath), {
|
|
2108
2205
|
id,
|
|
2109
2206
|
code,
|
|
2110
|
-
|
|
2207
|
+
type: "builtin"
|
|
2111
2208
|
}, defu2(options, {
|
|
2112
2209
|
mode: this.config.output.mode
|
|
2113
2210
|
}));
|
|
2114
2211
|
}
|
|
2115
2212
|
/**
|
|
2116
|
-
* Parses the source code and returns a {@link ParseResult} object.
|
|
2117
|
-
*
|
|
2118
|
-
* @param code - The source code to parse.
|
|
2119
|
-
* @param id - The unique identifier for the source file.
|
|
2120
|
-
* @param options - Optional parser options.
|
|
2121
|
-
* @returns The parsed {@link ParseResult} object.
|
|
2122
|
-
*/
|
|
2123
|
-
async parse(code, id, options = {}) {
|
|
2124
|
-
if (parseCache.has({
|
|
2125
|
-
code,
|
|
2126
|
-
options
|
|
2127
|
-
})) {
|
|
2128
|
-
return parseCache.get({
|
|
2129
|
-
code,
|
|
2130
|
-
options
|
|
2131
|
-
});
|
|
2132
|
-
}
|
|
2133
|
-
const result = await parseAsync(id, code, defu2(options ?? {}, {
|
|
2134
|
-
lang: hasFileExtension(id) ? void 0 : "ts",
|
|
2135
|
-
astType: hasFileExtension(id) ? void 0 : "ts",
|
|
2136
|
-
sourceType: "module",
|
|
2137
|
-
showSemanticErrors: false
|
|
2138
|
-
}));
|
|
2139
|
-
if (result.errors && result.errors.length > 0) {
|
|
2140
|
-
throw new Error(`Powerlines parsing errors in file: ${id}
|
|
2141
|
-
${result.errors.map((error) => ` [${error.severity}] ${error.message}${error.codeframe ? ` (${error.codeframe})` : ""}${error.helpMessage ? `
|
|
2142
|
-
Help: ${error.helpMessage}` : ""}`).join("\n")}`);
|
|
2143
|
-
}
|
|
2144
|
-
parseCache.set({
|
|
2145
|
-
code,
|
|
2146
|
-
options
|
|
2147
|
-
}, result);
|
|
2148
|
-
return result;
|
|
2149
|
-
}
|
|
2150
|
-
/**
|
|
2151
2213
|
* Update the context using a new user configuration options
|
|
2152
2214
|
*
|
|
2153
2215
|
* @param userConfig - The new user configuration options.
|
|
@@ -2335,7 +2397,7 @@ ${result.errors.map((error) => ` [${error.severity}] ${error.message}${error.co
|
|
|
2335
2397
|
tsconfig: appendPath("tsconfig.json", cacheKey.projectRoot),
|
|
2336
2398
|
sourceRoot: this.projectJson?.sourceRoot || appendPath("src", cacheKey.projectRoot),
|
|
2337
2399
|
output: {
|
|
2338
|
-
outputPath: joinPaths("dist", cacheKey.projectRoot),
|
|
2400
|
+
outputPath: cacheKey.projectRoot ? joinPaths(this.workspaceConfig?.directories?.build || "dist", cacheKey.projectRoot) : this.workspaceConfig?.directories?.build || "dist",
|
|
2339
2401
|
mode: "virtual",
|
|
2340
2402
|
dts: joinPaths(cacheKey.projectRoot, `${config.framework ?? "powerlines"}.d.ts`),
|
|
2341
2403
|
builtinPrefix: config.framework ?? "powerlines",
|
|
@@ -2441,1359 +2503,4 @@ ${result.errors.map((error) => ` [${error.severity}] ${error.message}${error.co
|
|
|
2441
2503
|
}
|
|
2442
2504
|
};
|
|
2443
2505
|
|
|
2444
|
-
|
|
2445
|
-
var PLUGIN_NON_HOOK_FIELDS = [
|
|
2446
|
-
"name",
|
|
2447
|
-
"enforce",
|
|
2448
|
-
"dedupe",
|
|
2449
|
-
"dependsOn",
|
|
2450
|
-
"applyToEnvironment"
|
|
2451
|
-
];
|
|
2452
|
-
async function callHook(context, hook, options, ...args) {
|
|
2453
|
-
const handlers = context.selectHooks(hook, options);
|
|
2454
|
-
if (handlers.length > 0) {
|
|
2455
|
-
context.log(LogLevelLabel.DEBUG, ` \u{1F9E9} Calling plugin hook: ${chalk4.bold.cyanBright(`${hook}${options?.order ? ` (${options.order})` : ""}`)}`);
|
|
2456
|
-
let results = [];
|
|
2457
|
-
if (options?.sequential === false) {
|
|
2458
|
-
results = await Promise.all(handlers.map(async (handler) => {
|
|
2459
|
-
if (!isFunction(handler)) {
|
|
2460
|
-
throw new Error(`Plugin hook handler for hook "${hook}" is not a function.`);
|
|
2461
|
-
}
|
|
2462
|
-
return Promise.resolve(handler.apply(null, ...args));
|
|
2463
|
-
}));
|
|
2464
|
-
} else {
|
|
2465
|
-
for (const handler of handlers) {
|
|
2466
|
-
if (!isFunction(handler)) {
|
|
2467
|
-
throw new Error(`Plugin hook handler for hook "${hook}" is not a function.`);
|
|
2468
|
-
}
|
|
2469
|
-
results.push(await Promise.resolve(handler.apply(null, ...args)));
|
|
2470
|
-
if (options?.result === "first" && isSet(results[results.length - 1])) {
|
|
2471
|
-
break;
|
|
2472
|
-
}
|
|
2473
|
-
}
|
|
2474
|
-
}
|
|
2475
|
-
const definedResults = results.filter((result) => isSet(result));
|
|
2476
|
-
if (definedResults.length > 0) {
|
|
2477
|
-
let mergedResult = void 0;
|
|
2478
|
-
for (const result of definedResults) {
|
|
2479
|
-
mergedResult = defu(result, mergedResult ?? {});
|
|
2480
|
-
}
|
|
2481
|
-
return mergedResult;
|
|
2482
|
-
}
|
|
2483
|
-
}
|
|
2484
|
-
return void 0;
|
|
2485
|
-
}
|
|
2486
|
-
__name(callHook, "callHook");
|
|
2487
|
-
|
|
2488
|
-
// src/internal/contexts/plugin-context.ts
|
|
2489
|
-
function createPluginContext(plugin, environment) {
|
|
2490
|
-
const normalizeMessage = /* @__PURE__ */ __name((message) => {
|
|
2491
|
-
return isString(message) ? message : message.message;
|
|
2492
|
-
}, "normalizeMessage");
|
|
2493
|
-
const log = environment.extendLog(plugin.name);
|
|
2494
|
-
const callHookFn = /* @__PURE__ */ __name(async (hook, options, ...args) => {
|
|
2495
|
-
return callHook(environment, hook, {
|
|
2496
|
-
sequential: true,
|
|
2497
|
-
...options
|
|
2498
|
-
}, ...args);
|
|
2499
|
-
}, "callHookFn");
|
|
2500
|
-
return new Proxy({}, {
|
|
2501
|
-
get(_, prop) {
|
|
2502
|
-
if (prop === "$$internal") {
|
|
2503
|
-
return {
|
|
2504
|
-
environment,
|
|
2505
|
-
callHook: callHookFn
|
|
2506
|
-
};
|
|
2507
|
-
}
|
|
2508
|
-
if (prop === "log" || prop === "logger") {
|
|
2509
|
-
return log;
|
|
2510
|
-
}
|
|
2511
|
-
if (prop === "error") {
|
|
2512
|
-
return (message) => {
|
|
2513
|
-
log(LogLevelLabel.ERROR, normalizeMessage(message));
|
|
2514
|
-
};
|
|
2515
|
-
}
|
|
2516
|
-
if (prop === "warn") {
|
|
2517
|
-
return (message) => {
|
|
2518
|
-
log(LogLevelLabel.WARN, normalizeMessage(message));
|
|
2519
|
-
};
|
|
2520
|
-
}
|
|
2521
|
-
return environment[prop];
|
|
2522
|
-
},
|
|
2523
|
-
set(_, prop, value) {
|
|
2524
|
-
if ([
|
|
2525
|
-
"$$internal",
|
|
2526
|
-
"environment",
|
|
2527
|
-
"config",
|
|
2528
|
-
"log",
|
|
2529
|
-
"logger",
|
|
2530
|
-
"error",
|
|
2531
|
-
"warn",
|
|
2532
|
-
"plugins",
|
|
2533
|
-
"hooks",
|
|
2534
|
-
"addPlugin",
|
|
2535
|
-
"selectHooks"
|
|
2536
|
-
].includes(prop)) {
|
|
2537
|
-
log(LogLevelLabel.WARN, `Cannot set read-only property "${String(prop)}"`);
|
|
2538
|
-
return false;
|
|
2539
|
-
}
|
|
2540
|
-
environment[prop] = value;
|
|
2541
|
-
return true;
|
|
2542
|
-
}
|
|
2543
|
-
});
|
|
2544
|
-
}
|
|
2545
|
-
__name(createPluginContext, "createPluginContext");
|
|
2546
|
-
|
|
2547
|
-
// src/internal/contexts/environment-context.ts
|
|
2548
|
-
var PowerlinesEnvironmentContext = class _PowerlinesEnvironmentContext extends PowerlinesContext {
|
|
2549
|
-
static {
|
|
2550
|
-
__name(this, "PowerlinesEnvironmentContext");
|
|
2551
|
-
}
|
|
2552
|
-
#hooks = {};
|
|
2553
|
-
/**
|
|
2554
|
-
* Create a new Storm context from the workspace root and user config.
|
|
2555
|
-
*
|
|
2556
|
-
* @param workspaceConfig - The root directory of the workspace.
|
|
2557
|
-
* @param config - The user configuration options.
|
|
2558
|
-
* @returns A promise that resolves to the new context.
|
|
2559
|
-
*/
|
|
2560
|
-
static async fromConfig(workspaceConfig, config) {
|
|
2561
|
-
const context = new _PowerlinesEnvironmentContext(config, workspaceConfig);
|
|
2562
|
-
await context.init();
|
|
2563
|
-
context.powerlinesPath = await resolvePackage("powerlines");
|
|
2564
|
-
if (!context.powerlinesPath) {
|
|
2565
|
-
throw new Error("Could not resolve `powerlines` package location.");
|
|
2566
|
-
}
|
|
2567
|
-
return context;
|
|
2568
|
-
}
|
|
2569
|
-
environment;
|
|
2570
|
-
plugins = [];
|
|
2571
|
-
/**
|
|
2572
|
-
* The resolved configuration options
|
|
2573
|
-
*/
|
|
2574
|
-
get config() {
|
|
2575
|
-
return super.config;
|
|
2576
|
-
}
|
|
2577
|
-
get hooks() {
|
|
2578
|
-
return this.#hooks;
|
|
2579
|
-
}
|
|
2580
|
-
async addPlugin(plugin) {
|
|
2581
|
-
let resolvedPlugin = plugin;
|
|
2582
|
-
if (plugin.applyToEnvironment) {
|
|
2583
|
-
const result = await Promise.resolve(plugin.applyToEnvironment(this.environment));
|
|
2584
|
-
if (!result || isObject(result) && Object.keys(result).length === 0) {
|
|
2585
|
-
return;
|
|
2586
|
-
}
|
|
2587
|
-
resolvedPlugin = isPlugin(result) ? result : plugin;
|
|
2588
|
-
}
|
|
2589
|
-
const context = createPluginContext(resolvedPlugin, this);
|
|
2590
|
-
this.plugins.push({
|
|
2591
|
-
plugin: resolvedPlugin,
|
|
2592
|
-
context
|
|
2593
|
-
});
|
|
2594
|
-
this.#hooks = Object.keys(resolvedPlugin).filter((key) => !PLUGIN_NON_HOOK_FIELDS.includes(key)).reduce((ret, key) => {
|
|
2595
|
-
const hook = key;
|
|
2596
|
-
const pluginHook = resolvedPlugin[hook];
|
|
2597
|
-
if (!isPluginHook(pluginHook)) {
|
|
2598
|
-
return ret;
|
|
2599
|
-
}
|
|
2600
|
-
if (!isHookExternal(hook)) {
|
|
2601
|
-
ret[hook] ??= {};
|
|
2602
|
-
if (resolvedPlugin.enforce) {
|
|
2603
|
-
ret[hook][`${resolvedPlugin.enforce}Enforced`] ??= [];
|
|
2604
|
-
addPluginHook(context, resolvedPlugin, pluginHook, ret[hook][`${resolvedPlugin.enforce}Enforced`]);
|
|
2605
|
-
return ret;
|
|
2606
|
-
}
|
|
2607
|
-
if (isFunction(pluginHook) || !pluginHook.order) {
|
|
2608
|
-
ret[hook].normal ??= [];
|
|
2609
|
-
addPluginHook(context, resolvedPlugin, pluginHook, ret[hook].normal);
|
|
2610
|
-
return ret;
|
|
2611
|
-
}
|
|
2612
|
-
ret[hook][`${pluginHook.order}Ordered`] ??= [];
|
|
2613
|
-
addPluginHook(context, resolvedPlugin, pluginHook, ret[hook][`${pluginHook.order}Ordered`]);
|
|
2614
|
-
} else {
|
|
2615
|
-
ret[hook] ??= [];
|
|
2616
|
-
ret[hook].push({
|
|
2617
|
-
plugin: resolvedPlugin,
|
|
2618
|
-
hook: getHookHandler(pluginHook).bind(context)
|
|
2619
|
-
});
|
|
2620
|
-
}
|
|
2621
|
-
return ret;
|
|
2622
|
-
}, this.hooks);
|
|
2623
|
-
}
|
|
2624
|
-
/**
|
|
2625
|
-
* Retrieves the hook handlers for a specific hook name
|
|
2626
|
-
*/
|
|
2627
|
-
selectHooks(hook, options) {
|
|
2628
|
-
const handlers = [];
|
|
2629
|
-
if (this.hooks[hook]) {
|
|
2630
|
-
if (!isHookExternal(hook)) {
|
|
2631
|
-
const hooks = this.hooks[hook];
|
|
2632
|
-
if (options?.order) {
|
|
2633
|
-
if (options?.order === "pre") {
|
|
2634
|
-
handlers.push(...(hooks.preOrdered ?? []).map((h) => h.handler));
|
|
2635
|
-
handlers.push(...(hooks.preEnforced ?? []).map((h) => h.handler));
|
|
2636
|
-
} else if (options?.order === "post") {
|
|
2637
|
-
handlers.push(...(hooks.postOrdered ?? []).map((h) => h.handler));
|
|
2638
|
-
handlers.push(...(hooks.postEnforced ?? []).map((h) => h.handler));
|
|
2639
|
-
} else {
|
|
2640
|
-
handlers.push(...(hooks.normal ?? []).map((h) => h.handler));
|
|
2641
|
-
}
|
|
2642
|
-
} else {
|
|
2643
|
-
handlers.push(...this.selectHooks(hook, {
|
|
2644
|
-
order: "pre"
|
|
2645
|
-
}));
|
|
2646
|
-
handlers.push(...this.selectHooks(hook, {
|
|
2647
|
-
order: "normal"
|
|
2648
|
-
}));
|
|
2649
|
-
handlers.push(...this.selectHooks(hook, {
|
|
2650
|
-
order: "post"
|
|
2651
|
-
}));
|
|
2652
|
-
}
|
|
2653
|
-
} else {
|
|
2654
|
-
handlers.push(...this.hooks[hook].map((h) => h.handler));
|
|
2655
|
-
}
|
|
2656
|
-
}
|
|
2657
|
-
return handlers;
|
|
2658
|
-
}
|
|
2659
|
-
constructor(config, workspaceConfig) {
|
|
2660
|
-
super(workspaceConfig);
|
|
2661
|
-
this.resolvedConfig = config;
|
|
2662
|
-
}
|
|
2663
|
-
};
|
|
2664
|
-
|
|
2665
|
-
// src/internal/contexts/api-context.ts
|
|
2666
|
-
var PowerlinesAPIContext = class _PowerlinesAPIContext extends PowerlinesContext {
|
|
2667
|
-
static {
|
|
2668
|
-
__name(this, "PowerlinesAPIContext");
|
|
2669
|
-
}
|
|
2670
|
-
#environments = {};
|
|
2671
|
-
#plugins = [];
|
|
2672
|
-
#log;
|
|
2673
|
-
/**
|
|
2674
|
-
* Create a new Storm context from the workspace root and user config.
|
|
2675
|
-
*
|
|
2676
|
-
* @param workspaceRoot - The root directory of the workspace.
|
|
2677
|
-
* @param config - The user configuration options.
|
|
2678
|
-
* @returns A promise that resolves to the new context.
|
|
2679
|
-
*/
|
|
2680
|
-
static async from(workspaceRoot, config) {
|
|
2681
|
-
const context = new _PowerlinesAPIContext(await loadWorkspaceConfig(workspaceRoot, config.root));
|
|
2682
|
-
await context.withUserConfig(config);
|
|
2683
|
-
context.powerlinesPath = await resolvePackage("powerlines");
|
|
2684
|
-
if (!context.powerlinesPath) {
|
|
2685
|
-
throw new Error("Could not resolve `powerlines` package location.");
|
|
2686
|
-
}
|
|
2687
|
-
return context;
|
|
2688
|
-
}
|
|
2689
|
-
/**
|
|
2690
|
-
* A record of all environments by name
|
|
2691
|
-
*/
|
|
2692
|
-
get environments() {
|
|
2693
|
-
return this.#environments;
|
|
2694
|
-
}
|
|
2695
|
-
get log() {
|
|
2696
|
-
if (!this.#log) {
|
|
2697
|
-
this.#log = this.createLog("engine");
|
|
2698
|
-
}
|
|
2699
|
-
return this.#log;
|
|
2700
|
-
}
|
|
2701
|
-
get plugins() {
|
|
2702
|
-
return this.#plugins;
|
|
2703
|
-
}
|
|
2704
|
-
constructor(workspaceConfig) {
|
|
2705
|
-
super(workspaceConfig);
|
|
2706
|
-
}
|
|
2707
|
-
/**
|
|
2708
|
-
* Initialize the context with the provided configuration options
|
|
2709
|
-
*
|
|
2710
|
-
* @param config - The partial user configuration to use for initialization.
|
|
2711
|
-
*/
|
|
2712
|
-
async init(config = {}) {
|
|
2713
|
-
await super.init(config);
|
|
2714
|
-
await Promise.all(toArray(this.config.userConfig.environments && Object.keys(this.config.userConfig.environments).length > 0 ? Object.keys(this.config.userConfig.environments).map((name) => createEnvironment(name, this.config.userConfig)) : createDefaultEnvironment(this.config.userConfig)).map(async (env) => {
|
|
2715
|
-
this.#environments[env.name] = await this.in(env);
|
|
2716
|
-
}));
|
|
2717
|
-
}
|
|
2718
|
-
/**
|
|
2719
|
-
* A function to copy the context and update the fields for a specific environment
|
|
2720
|
-
*
|
|
2721
|
-
* @param environment - The environment configuration to use.
|
|
2722
|
-
* @returns A new context instance with the updated environment.
|
|
2723
|
-
*/
|
|
2724
|
-
async in(environment) {
|
|
2725
|
-
let context;
|
|
2726
|
-
if (this.environments[environment.name]) {
|
|
2727
|
-
context = this.environments[environment.name];
|
|
2728
|
-
} else {
|
|
2729
|
-
context = await PowerlinesEnvironmentContext.fromConfig(this.workspaceConfig, this.config);
|
|
2730
|
-
}
|
|
2731
|
-
if (isSetObject(this.config.inlineConfig)) {
|
|
2732
|
-
await context.withInlineConfig(this.config.inlineConfig);
|
|
2733
|
-
}
|
|
2734
|
-
context.environment = environment;
|
|
2735
|
-
context.plugins = [];
|
|
2736
|
-
for (const plugin of this.plugins) {
|
|
2737
|
-
await context.addPlugin(plugin);
|
|
2738
|
-
}
|
|
2739
|
-
return context;
|
|
2740
|
-
}
|
|
2741
|
-
async addPlugin(plugin) {
|
|
2742
|
-
this.plugins.push(plugin);
|
|
2743
|
-
await Promise.all(Object.keys(this.environments).map(async (name) => {
|
|
2744
|
-
await this.environments[name].addPlugin(plugin);
|
|
2745
|
-
}));
|
|
2746
|
-
}
|
|
2747
|
-
async getEnvironment(name) {
|
|
2748
|
-
let environment;
|
|
2749
|
-
if (name) {
|
|
2750
|
-
environment = this.environments[name];
|
|
2751
|
-
}
|
|
2752
|
-
if (Object.keys(this.environments).length === 1) {
|
|
2753
|
-
environment = this.environments[Object.keys(this.environments)[0]];
|
|
2754
|
-
this.log(LogLevelLabel.DEBUG, `Applying the only configured environment: ${chalk4.bold.cyanBright(environment?.environment.name)}`);
|
|
2755
|
-
}
|
|
2756
|
-
if (!environment) {
|
|
2757
|
-
if (name) {
|
|
2758
|
-
throw new Error(`Environment "${name}" not found.`);
|
|
2759
|
-
}
|
|
2760
|
-
environment = await this.in(createDefaultEnvironment(this.config.userConfig));
|
|
2761
|
-
this.log(LogLevelLabel.WARN, `No environment specified, and no default environment found. Using a temporary default environment: ${chalk4.bold.cyanBright(environment?.environment.name)}`);
|
|
2762
|
-
}
|
|
2763
|
-
return environment;
|
|
2764
|
-
}
|
|
2765
|
-
async getEnvironmentSafe(name) {
|
|
2766
|
-
try {
|
|
2767
|
-
return await this.getEnvironment(name);
|
|
2768
|
-
} catch {
|
|
2769
|
-
return void 0;
|
|
2770
|
-
}
|
|
2771
|
-
}
|
|
2772
|
-
};
|
|
2773
|
-
function formatTypes(code) {
|
|
2774
|
-
return code.replace(
|
|
2775
|
-
// eslint-disable-next-line regexp/no-super-linear-backtracking
|
|
2776
|
-
/import\s*(?:type\s*)?\{?[\w,\s]*(?:\}\s*)?from\s*(?:'|")@?[a-zA-Z0-9-\\/.]*(?:'|");?/g,
|
|
2777
|
-
""
|
|
2778
|
-
).replaceAll("#private;", "").replace(/__Ω/g, "");
|
|
2779
|
-
}
|
|
2780
|
-
__name(formatTypes, "formatTypes");
|
|
2781
|
-
async function emitTypes(context, tsconfig, files) {
|
|
2782
|
-
context.log(LogLevelLabel.TRACE, "Creating the TypeScript compiler host");
|
|
2783
|
-
const program = createProgram(files, tsconfig.options, createCompilerHost(tsconfig.options));
|
|
2784
|
-
context.log(LogLevelLabel.TRACE, `Running the TypeScript compiler for ${context.builtins.length} built-in runtime files.`);
|
|
2785
|
-
let builtinModules = "";
|
|
2786
|
-
const emitResult = program.emit(void 0, (fileName, text, _, __, sourceFiles, _data) => {
|
|
2787
|
-
const sourceFile = sourceFiles?.[0];
|
|
2788
|
-
if (sourceFile?.fileName && !fileName.endsWith(".map")) {
|
|
2789
|
-
if (context.builtins.some((file) => file === sourceFile.fileName || context.fs.metadata[file]?.id && context.fs.metadata[file]?.id === sourceFile.fileName)) {
|
|
2790
|
-
builtinModules += `
|
|
2791
|
-
declare module "${context.fs.resolve(sourceFile.fileName)}" {
|
|
2792
|
-
${text.trim().replace(/^\s*export\s*declare\s*/gm, "export ").replace(/^\s*declare\s*/gm, "")}
|
|
2793
|
-
}
|
|
2794
|
-
`;
|
|
2795
|
-
}
|
|
2796
|
-
}
|
|
2797
|
-
}, void 0, true);
|
|
2798
|
-
const diagnostics = getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
|
|
2799
|
-
const diagnosticMessages = [];
|
|
2800
|
-
diagnostics.forEach((diagnostic) => {
|
|
2801
|
-
if (diagnostic.file) {
|
|
2802
|
-
const { line, character } = getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start);
|
|
2803
|
-
const message = flattenDiagnosticMessageText(diagnostic.messageText, "\n");
|
|
2804
|
-
diagnosticMessages.push(`${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`);
|
|
2805
|
-
} else {
|
|
2806
|
-
const message = flattenDiagnosticMessageText(diagnostic.messageText, "\n");
|
|
2807
|
-
diagnosticMessages.push(message);
|
|
2808
|
-
}
|
|
2809
|
-
});
|
|
2810
|
-
const diagnosticMessage = diagnosticMessages.join("\n");
|
|
2811
|
-
if (diagnosticMessage) {
|
|
2812
|
-
throw new Error(`TypeScript compilation failed:
|
|
2813
|
-
|
|
2814
|
-
${diagnosticMessage.length > 5e3 ? `${diagnosticMessage.slice(0, 5e3)}...` : diagnosticMessage}`);
|
|
2815
|
-
}
|
|
2816
|
-
return formatTypes(builtinModules);
|
|
2817
|
-
}
|
|
2818
|
-
__name(emitTypes, "emitTypes");
|
|
2819
|
-
async function installPackage(context, packageName, dev = false) {
|
|
2820
|
-
if (!await isPackageListed(getPackageName(packageName), {
|
|
2821
|
-
cwd: context.config.projectRoot
|
|
2822
|
-
})) {
|
|
2823
|
-
if (context.config.skipInstalls !== true && !process.env.POWERLINES_LOCAL) {
|
|
2824
|
-
context.log(LogLevelLabel.WARN, `The package "${packageName}" is not installed. It will be installed automatically.`);
|
|
2825
|
-
const result = await install(packageName, {
|
|
2826
|
-
cwd: context.config.projectRoot,
|
|
2827
|
-
dev
|
|
2828
|
-
});
|
|
2829
|
-
if (isNumber(result.exitCode) && result.exitCode > 0) {
|
|
2830
|
-
context.log(LogLevelLabel.ERROR, result.stderr);
|
|
2831
|
-
throw new Error(`An error occurred while installing the package "${packageName}"`);
|
|
2832
|
-
}
|
|
2833
|
-
} else {
|
|
2834
|
-
context.log(LogLevelLabel.WARN, `The package "${packageName}" is not installed. Since the "skipInstalls" option is set to true, it will not be installed automatically.`);
|
|
2835
|
-
}
|
|
2836
|
-
} else if (hasPackageVersion(packageName) && !process.env.POWERLINES_SKIP_VERSION_CHECK) {
|
|
2837
|
-
const isMatching = await doesPackageMatch(getPackageName(packageName), getPackageVersion(packageName), context.config.projectRoot);
|
|
2838
|
-
if (!isMatching) {
|
|
2839
|
-
const packageListing = await getPackageListing(getPackageName(packageName), {
|
|
2840
|
-
cwd: context.config.projectRoot
|
|
2841
|
-
});
|
|
2842
|
-
if (!packageListing?.version.startsWith("catalog:") && !packageListing?.version.startsWith("workspace:")) {
|
|
2843
|
-
context.log(LogLevelLabel.WARN, `The package "${getPackageName(packageName)}" is installed but does not match the expected version ${getPackageVersion(packageName)} (installed version: ${packageListing?.version || "<Unknown>"}). Please ensure this is intentional before proceeding. Note: You can skip this validation with the "STORM_STACK_SKIP_VERSION_CHECK" environment variable.`);
|
|
2844
|
-
}
|
|
2845
|
-
}
|
|
2846
|
-
}
|
|
2847
|
-
}
|
|
2848
|
-
__name(installPackage, "installPackage");
|
|
2849
|
-
|
|
2850
|
-
// src/internal/helpers/install-dependencies.ts
|
|
2851
|
-
async function installDependencies(context) {
|
|
2852
|
-
context.log(LogLevelLabel.TRACE, `Checking and installing missing project dependencies.`);
|
|
2853
|
-
context.dependencies ??= {};
|
|
2854
|
-
context.devDependencies ??= {};
|
|
2855
|
-
if (Object.keys(context.dependencies).length === 0 && Object.keys(context.devDependencies).length === 0) {
|
|
2856
|
-
context.log(LogLevelLabel.TRACE, `No dependencies or devDependencies to install. Skipping installation step.`);
|
|
2857
|
-
return;
|
|
2858
|
-
}
|
|
2859
|
-
context.log(LogLevelLabel.DEBUG, `The following packages are required:
|
|
2860
|
-
Dependencies:
|
|
2861
|
-
${Object.entries(context.dependencies).map(([name, version]) => `- ${name}@${String(version)}`).join(" \n")}
|
|
2862
|
-
|
|
2863
|
-
DevDependencies:
|
|
2864
|
-
${Object.entries(context.devDependencies).map(([name, version]) => `- ${name}@${String(version)}`).join(" \n")}`);
|
|
2865
|
-
await Promise.all([
|
|
2866
|
-
Promise.all(Object.entries(context.dependencies).map(async ([name, version]) => installPackage(context, `${getPackageName(name)}@${String(version)}`, false))),
|
|
2867
|
-
Promise.all(Object.entries(context.devDependencies).map(async ([name, version]) => installPackage(context, `${getPackageName(name)}@${String(version)}`, true)))
|
|
2868
|
-
]);
|
|
2869
|
-
}
|
|
2870
|
-
__name(installDependencies, "installDependencies");
|
|
2871
|
-
async function resolveTsconfigChanges(context) {
|
|
2872
|
-
const tsconfig = getParsedTypeScriptConfig(context.workspaceConfig.workspaceRoot, context.config.projectRoot, context.config.tsconfig, context.config.tsconfigRaw);
|
|
2873
|
-
const tsconfigFilePath = getTsconfigFilePath(context.workspaceConfig.workspaceRoot, context.config.projectRoot, context.config.tsconfig);
|
|
2874
|
-
const tsconfigJson = await readJsonFile(tsconfigFilePath);
|
|
2875
|
-
tsconfigJson.compilerOptions ??= {};
|
|
2876
|
-
const extendedTsconfig = await loadTsConfig(tsconfigFilePath);
|
|
2877
|
-
extendedTsconfig.compilerOptions ??= {};
|
|
2878
|
-
if (tsconfigJson.reflection !== true) {
|
|
2879
|
-
tsconfigJson.reflection = true;
|
|
2880
|
-
}
|
|
2881
|
-
if (tsconfig.options.experimentalDecorators !== true) {
|
|
2882
|
-
tsconfigJson.compilerOptions.experimentalDecorators = true;
|
|
2883
|
-
}
|
|
2884
|
-
if (tsconfig.options.emitDecoratorMetadata !== true) {
|
|
2885
|
-
tsconfigJson.compilerOptions.emitDecoratorMetadata = true;
|
|
2886
|
-
}
|
|
2887
|
-
if (context.config.output.dts) {
|
|
2888
|
-
const dtsFilePath = context.config.output.dts ? context.config.output.dts.startsWith(context.workspaceConfig.workspaceRoot) ? context.config.output.dts : joinPaths$1(context.workspaceConfig.workspaceRoot, context.config.output.dts) : joinPaths$1(context.workspaceConfig.workspaceRoot, context.config.projectRoot, "storm.d.ts");
|
|
2889
|
-
const dtsRelativePath = joinPaths$1(relativePath(joinPaths$1(context.workspaceConfig.workspaceRoot, context.config.projectRoot), findFilePath(dtsFilePath)), findFileName(dtsFilePath));
|
|
2890
|
-
if (!tsconfigJson.include?.some((filePattern) => isIncludeMatchFound(filePattern, [
|
|
2891
|
-
dtsFilePath,
|
|
2892
|
-
dtsRelativePath,
|
|
2893
|
-
"storm.d.ts"
|
|
2894
|
-
]))) {
|
|
2895
|
-
tsconfigJson.include ??= [];
|
|
2896
|
-
tsconfigJson.include.push(dtsRelativePath.startsWith("./") ? dtsRelativePath.slice(2) : dtsRelativePath);
|
|
2897
|
-
}
|
|
2898
|
-
}
|
|
2899
|
-
if (!tsconfig.options.lib?.some((lib) => [
|
|
2900
|
-
"lib.esnext.d.ts",
|
|
2901
|
-
"lib.es2021.d.ts",
|
|
2902
|
-
"lib.es2022.d.ts",
|
|
2903
|
-
"lib.es2023.d.ts"
|
|
2904
|
-
].includes(lib.toLowerCase()))) {
|
|
2905
|
-
tsconfigJson.compilerOptions.lib ??= [];
|
|
2906
|
-
tsconfigJson.compilerOptions.lib.push("esnext");
|
|
2907
|
-
}
|
|
2908
|
-
if (tsconfig.options.module !== ts.ModuleKind.ESNext) {
|
|
2909
|
-
tsconfigJson.compilerOptions.module = "ESNext";
|
|
2910
|
-
}
|
|
2911
|
-
if (!tsconfig.options.target || ![
|
|
2912
|
-
ts.ScriptTarget.ESNext,
|
|
2913
|
-
ts.ScriptTarget.ES2024,
|
|
2914
|
-
ts.ScriptTarget.ES2023,
|
|
2915
|
-
ts.ScriptTarget.ES2022,
|
|
2916
|
-
ts.ScriptTarget.ES2021
|
|
2917
|
-
].includes(tsconfig.options.target)) {
|
|
2918
|
-
tsconfigJson.compilerOptions.target = "ESNext";
|
|
2919
|
-
}
|
|
2920
|
-
if (tsconfig.options.moduleResolution !== ts.ModuleResolutionKind.Bundler) {
|
|
2921
|
-
tsconfigJson.compilerOptions.moduleResolution = "Bundler";
|
|
2922
|
-
}
|
|
2923
|
-
if (tsconfig.options.moduleDetection !== ts.ModuleDetectionKind.Force) {
|
|
2924
|
-
tsconfigJson.compilerOptions.moduleDetection = "force";
|
|
2925
|
-
}
|
|
2926
|
-
if (tsconfig.options.allowSyntheticDefaultImports !== true) {
|
|
2927
|
-
tsconfigJson.compilerOptions.allowSyntheticDefaultImports = true;
|
|
2928
|
-
}
|
|
2929
|
-
if (tsconfig.options.noImplicitOverride !== true) {
|
|
2930
|
-
tsconfigJson.compilerOptions.noImplicitOverride = true;
|
|
2931
|
-
}
|
|
2932
|
-
if (tsconfig.options.noUncheckedIndexedAccess !== true) {
|
|
2933
|
-
tsconfigJson.compilerOptions.noUncheckedIndexedAccess = true;
|
|
2934
|
-
}
|
|
2935
|
-
if (tsconfig.options.skipLibCheck !== true) {
|
|
2936
|
-
tsconfigJson.compilerOptions.skipLibCheck = true;
|
|
2937
|
-
}
|
|
2938
|
-
if (tsconfig.options.resolveJsonModule !== true) {
|
|
2939
|
-
tsconfigJson.compilerOptions.resolveJsonModule = true;
|
|
2940
|
-
}
|
|
2941
|
-
if (tsconfig.options.isolatedModules !== true) {
|
|
2942
|
-
tsconfigJson.compilerOptions.isolatedModules = true;
|
|
2943
|
-
}
|
|
2944
|
-
if (tsconfig.options.verbatimModuleSyntax !== false) {
|
|
2945
|
-
tsconfigJson.compilerOptions.verbatimModuleSyntax = false;
|
|
2946
|
-
}
|
|
2947
|
-
if (tsconfig.options.allowJs !== true) {
|
|
2948
|
-
tsconfigJson.compilerOptions.allowJs = true;
|
|
2949
|
-
}
|
|
2950
|
-
if (tsconfig.options.esModuleInterop !== true) {
|
|
2951
|
-
tsconfigJson.compilerOptions.esModuleInterop = true;
|
|
2952
|
-
}
|
|
2953
|
-
if (tsconfig.options.declaration !== true) {
|
|
2954
|
-
tsconfigJson.compilerOptions.declaration = true;
|
|
2955
|
-
}
|
|
2956
|
-
if (context.environment.consumer === "client") {
|
|
2957
|
-
if (tsconfig.options.jsx !== ts.JsxEmit.ReactJSX) {
|
|
2958
|
-
tsconfigJson.compilerOptions.jsx = "react-jsx";
|
|
2959
|
-
}
|
|
2960
|
-
if (!tsconfig.options.lib?.some((lib) => lib.toLowerCase() !== "dom")) {
|
|
2961
|
-
tsconfigJson.compilerOptions.lib ??= [];
|
|
2962
|
-
tsconfigJson.compilerOptions.lib.push("dom");
|
|
2963
|
-
}
|
|
2964
|
-
if (!tsconfig.options.lib?.some((lib) => lib.toLowerCase() !== "dom.iterable")) {
|
|
2965
|
-
tsconfigJson.compilerOptions.lib ??= [];
|
|
2966
|
-
tsconfigJson.compilerOptions.lib.push("dom.iterable");
|
|
2967
|
-
}
|
|
2968
|
-
} else if (context.config.build.platform === "node") {
|
|
2969
|
-
if (!tsconfig.options.types?.some((type) => type.toLowerCase() === "node" || type.toLowerCase() === "@types/node")) {
|
|
2970
|
-
tsconfigJson.compilerOptions.types ??= [];
|
|
2971
|
-
tsconfigJson.compilerOptions.types.push("node");
|
|
2972
|
-
}
|
|
2973
|
-
}
|
|
2974
|
-
return tsconfigJson;
|
|
2975
|
-
}
|
|
2976
|
-
__name(resolveTsconfigChanges, "resolveTsconfigChanges");
|
|
2977
|
-
async function initializeTsconfig(context) {
|
|
2978
|
-
context.log(LogLevelLabel.TRACE, "Initializing TypeScript configuration (tsconfig.json) for the Powerlines project.");
|
|
2979
|
-
if (!isPackageExists("typescript")) {
|
|
2980
|
-
throw new Error('The TypeScript package is not installed. Please install the package using the command: "npm install typescript --save-dev"');
|
|
2981
|
-
}
|
|
2982
|
-
const tsconfigFilePath = getTsconfigFilePath(context.workspaceConfig.workspaceRoot, context.config.projectRoot, context.config.tsconfig);
|
|
2983
|
-
context.tsconfig.originalTsconfigJson = await readJsonFile(tsconfigFilePath);
|
|
2984
|
-
context.tsconfig.tsconfigJson = await resolveTsconfigChanges(context);
|
|
2985
|
-
await context.fs.writeFile(tsconfigFilePath, StormJSON.stringify(context.tsconfig.tsconfigJson), {
|
|
2986
|
-
mode: "fs"
|
|
2987
|
-
});
|
|
2988
|
-
context.tsconfig = getParsedTypeScriptConfig(context.workspaceConfig.workspaceRoot, context.config.projectRoot, context.config.tsconfig, context.config.tsconfigRaw, context.tsconfig.originalTsconfigJson);
|
|
2989
|
-
}
|
|
2990
|
-
__name(initializeTsconfig, "initializeTsconfig");
|
|
2991
|
-
async function resolveTsconfig(context) {
|
|
2992
|
-
const updateTsconfigJson = await readJsonFile(context.tsconfig.tsconfigFilePath);
|
|
2993
|
-
if (updateTsconfigJson?.compilerOptions?.types && Array.isArray(updateTsconfigJson.compilerOptions.types) && !updateTsconfigJson.compilerOptions.types.length) {
|
|
2994
|
-
delete updateTsconfigJson.compilerOptions.types;
|
|
2995
|
-
}
|
|
2996
|
-
const result = getObjectDiff(context.tsconfig.originalTsconfigJson, updateTsconfigJson, {
|
|
2997
|
-
ignoreArrayOrder: true,
|
|
2998
|
-
showOnly: {
|
|
2999
|
-
statuses: [
|
|
3000
|
-
"added",
|
|
3001
|
-
"deleted",
|
|
3002
|
-
"updated"
|
|
3003
|
-
],
|
|
3004
|
-
granularity: "deep"
|
|
3005
|
-
}
|
|
3006
|
-
});
|
|
3007
|
-
const changes = [];
|
|
3008
|
-
const getChanges = /* @__PURE__ */ __name((difference, property) => {
|
|
3009
|
-
if (difference.status === "added" || difference.status === "deleted" || difference.status === "updated") {
|
|
3010
|
-
if (difference.diff) {
|
|
3011
|
-
for (const diff of difference.diff) {
|
|
3012
|
-
getChanges(diff, property ? `${property}.${difference.property}` : difference.property);
|
|
3013
|
-
}
|
|
3014
|
-
} else {
|
|
3015
|
-
changes.push({
|
|
3016
|
-
field: property ? `${property}.${difference.property}` : difference.property,
|
|
3017
|
-
status: difference.status,
|
|
3018
|
-
previous: difference.status === "added" ? "---" : StormJSON.stringify(difference.previousValue),
|
|
3019
|
-
current: difference.status === "deleted" ? "---" : StormJSON.stringify(difference.currentValue)
|
|
3020
|
-
});
|
|
3021
|
-
}
|
|
3022
|
-
}
|
|
3023
|
-
}, "getChanges");
|
|
3024
|
-
for (const diff of result.diff) {
|
|
3025
|
-
getChanges(diff);
|
|
3026
|
-
}
|
|
3027
|
-
if (changes.length > 0) {
|
|
3028
|
-
context.log(LogLevelLabel.WARN, `Updating the following configuration values in "${context.tsconfig.tsconfigFilePath}" file:
|
|
3029
|
-
|
|
3030
|
-
${changes.map((change, i) => `${chalk4.bold.whiteBright(`${i + 1}. ${titleCase(change.status)} the ${change.field} field: `)}
|
|
3031
|
-
${chalk4.red(` - Previous: ${change.previous} `)}
|
|
3032
|
-
${chalk4.green(` - Updated: ${change.current} `)}
|
|
3033
|
-
`).join("\n")}
|
|
3034
|
-
`);
|
|
3035
|
-
}
|
|
3036
|
-
await writeFile(context.log, context.tsconfig.tsconfigFilePath, StormJSON.stringify(updateTsconfigJson));
|
|
3037
|
-
context.tsconfig = getParsedTypeScriptConfig(context.workspaceConfig.workspaceRoot, context.config.projectRoot, context.config.tsconfig);
|
|
3038
|
-
if (!context.tsconfig) {
|
|
3039
|
-
throw new Error("Failed to parse the TypeScript configuration file.");
|
|
3040
|
-
}
|
|
3041
|
-
context.tsconfig.tsconfigJson.compilerOptions ??= {};
|
|
3042
|
-
context.tsconfig.tsconfigJson.compilerOptions.strict = false;
|
|
3043
|
-
}
|
|
3044
|
-
__name(resolveTsconfig, "resolveTsconfig");
|
|
3045
|
-
|
|
3046
|
-
// src/api.ts
|
|
3047
|
-
var PowerlinesAPI = class _PowerlinesAPI {
|
|
3048
|
-
static {
|
|
3049
|
-
__name(this, "PowerlinesAPI");
|
|
3050
|
-
}
|
|
3051
|
-
/**
|
|
3052
|
-
* The Powerlines context
|
|
3053
|
-
*/
|
|
3054
|
-
#context;
|
|
3055
|
-
/**
|
|
3056
|
-
* The Powerlines context
|
|
3057
|
-
*/
|
|
3058
|
-
get context() {
|
|
3059
|
-
return this.#context;
|
|
3060
|
-
}
|
|
3061
|
-
/**
|
|
3062
|
-
* Create a new Powerlines API instance
|
|
3063
|
-
*
|
|
3064
|
-
* @param context - The Powerlines context
|
|
3065
|
-
*/
|
|
3066
|
-
constructor(context) {
|
|
3067
|
-
this.#context = context;
|
|
3068
|
-
}
|
|
3069
|
-
/**
|
|
3070
|
-
* Initialize the Powerlines API
|
|
3071
|
-
*/
|
|
3072
|
-
static async from(workspaceRoot, config) {
|
|
3073
|
-
const api = new _PowerlinesAPI(await PowerlinesAPIContext.from(workspaceRoot, config));
|
|
3074
|
-
for (const plugin of api.context.config.plugins ?? []) {
|
|
3075
|
-
await api.#addPlugin(plugin);
|
|
3076
|
-
}
|
|
3077
|
-
if (api.context.plugins.length === 0) {
|
|
3078
|
-
api.context.log(LogLevelLabel.WARN, "No Powerlines plugins were specified in the options. Please ensure this is correct, as it is generally not recommended.");
|
|
3079
|
-
}
|
|
3080
|
-
const pluginConfig = await callHook(await api.context.getEnvironment(), "config", {
|
|
3081
|
-
sequential: true,
|
|
3082
|
-
result: "merge"
|
|
3083
|
-
});
|
|
3084
|
-
await api.context.withUserConfig(pluginConfig, {
|
|
3085
|
-
isHighPriority: false
|
|
3086
|
-
});
|
|
3087
|
-
return api;
|
|
3088
|
-
}
|
|
3089
|
-
/**
|
|
3090
|
-
* Prepare the Powerlines API
|
|
3091
|
-
*/
|
|
3092
|
-
async prepare(inlineConfig = {
|
|
3093
|
-
command: "prepare"
|
|
3094
|
-
}) {
|
|
3095
|
-
this.context.log(LogLevelLabel.TRACE, " \u{1F3D7}\uFE0F Preparing the Powerlines project");
|
|
3096
|
-
this.context.log(LogLevelLabel.TRACE, " \u2699\uFE0F Aggregating configuration options for the Powerlines project");
|
|
3097
|
-
await this.context.withInlineConfig(inlineConfig);
|
|
3098
|
-
await this.#executeEnvironments(async (context) => {
|
|
3099
|
-
context.log(LogLevelLabel.TRACE, `Initializing the processing options for the Powerlines project.`);
|
|
3100
|
-
await this.callPreHook(context, "configResolved");
|
|
3101
|
-
await initializeTsconfig(context);
|
|
3102
|
-
await this.callNormalHook(context, "configResolved");
|
|
3103
|
-
context.log(LogLevelLabel.DEBUG, `The configuration provided ${toArray(context.config.entry).length} entry point(s), Powerlines has found ${context.entry.length} entry files(s) for the ${context.config.title} project${context.entry.length > 0 && context.entry.length < 10 ? `:
|
|
3104
|
-
${context.entry.map((entry) => `- ${entry.input.file || entry.file}${entry.output ? ` -> ${entry.output}` : ""}`).join(" \n")}` : ""}.`);
|
|
3105
|
-
await resolveTsconfig(context);
|
|
3106
|
-
await installDependencies(context);
|
|
3107
|
-
await this.callPostHook(context, "configResolved");
|
|
3108
|
-
if (context.config.build.polyfill) {
|
|
3109
|
-
context.config.build.polyfill = context.config.build.polyfill.map((polyfill) => replacePathTokens(context, polyfill));
|
|
3110
|
-
}
|
|
3111
|
-
context.log(LogLevelLabel.TRACE, `Powerlines configuration has been resolved:
|
|
3112
|
-
|
|
3113
|
-
${formatLogMessage(context.config)}`);
|
|
3114
|
-
context.fs[__VFS_PATCH__]();
|
|
3115
|
-
await writeMetaFile(context);
|
|
3116
|
-
context.persistedMeta = context.meta;
|
|
3117
|
-
if (!existsSync(context.cachePath)) {
|
|
3118
|
-
await createDirectory(context.cachePath);
|
|
3119
|
-
}
|
|
3120
|
-
if (!existsSync(context.dataPath)) {
|
|
3121
|
-
await createDirectory(context.dataPath);
|
|
3122
|
-
}
|
|
3123
|
-
await this.callPreHook(context, "prepare");
|
|
3124
|
-
await this.callNormalHook(context, "prepare");
|
|
3125
|
-
if (context.config.output.dts !== false) {
|
|
3126
|
-
context.log(LogLevelLabel.TRACE, `Preparing the TypeScript definitions for the Powerlines project.`);
|
|
3127
|
-
context.log(LogLevelLabel.TRACE, "Transforming built-ins runtime modules files.");
|
|
3128
|
-
const builtinFilePaths = await Promise.all((await context.getBuiltins()).map(async (file) => {
|
|
3129
|
-
const result2 = await transformAsync(file.code.toString(), {
|
|
3130
|
-
highlightCode: true,
|
|
3131
|
-
code: true,
|
|
3132
|
-
ast: false,
|
|
3133
|
-
cloneInputAst: false,
|
|
3134
|
-
comments: true,
|
|
3135
|
-
sourceType: "module",
|
|
3136
|
-
configFile: false,
|
|
3137
|
-
babelrc: false,
|
|
3138
|
-
envName: context.config.mode,
|
|
3139
|
-
caller: {
|
|
3140
|
-
name: "powerlines"
|
|
3141
|
-
},
|
|
3142
|
-
...context.config.transform.babel,
|
|
3143
|
-
filename: file.path,
|
|
3144
|
-
plugins: [
|
|
3145
|
-
[
|
|
3146
|
-
"@babel/plugin-syntax-typescript"
|
|
3147
|
-
],
|
|
3148
|
-
[
|
|
3149
|
-
moduleResolverBabelPlugin(context)
|
|
3150
|
-
]
|
|
3151
|
-
]
|
|
3152
|
-
});
|
|
3153
|
-
if (!result2?.code) {
|
|
3154
|
-
throw new Error(`Powerlines - Generate Types failed to compile ${file.id}`);
|
|
3155
|
-
}
|
|
3156
|
-
context.log(LogLevelLabel.TRACE, `Writing transformed built-in runtime file ${file.id}.`);
|
|
3157
|
-
await context.writeBuiltin(result2.code, file.id, file.path);
|
|
3158
|
-
return file.path;
|
|
3159
|
-
}));
|
|
3160
|
-
const typescriptPath = await resolvePackage("typescript");
|
|
3161
|
-
if (!typescriptPath) {
|
|
3162
|
-
throw new Error("Could not resolve TypeScript package location. Please ensure TypeScript is installed.");
|
|
3163
|
-
}
|
|
3164
|
-
const files = builtinFilePaths.reduce((ret, fileName) => {
|
|
3165
|
-
const formatted = replacePath(fileName, context.workspaceConfig.workspaceRoot);
|
|
3166
|
-
if (!ret.includes(formatted)) {
|
|
3167
|
-
ret.push(formatted);
|
|
3168
|
-
}
|
|
3169
|
-
return ret;
|
|
3170
|
-
}, [
|
|
3171
|
-
joinPaths$1(typescriptPath, "lib", "lib.esnext.full.d.ts")
|
|
3172
|
-
]);
|
|
3173
|
-
context.log(LogLevelLabel.TRACE, "Parsing TypeScript configuration for the Powerlines project.");
|
|
3174
|
-
const resolvedTsconfig = getParsedTypeScriptConfig(context.workspaceConfig.workspaceRoot, context.config.projectRoot, context.tsconfig.tsconfigFilePath, defu2({
|
|
3175
|
-
compilerOptions: {
|
|
3176
|
-
strict: false,
|
|
3177
|
-
noEmit: false,
|
|
3178
|
-
declaration: true,
|
|
3179
|
-
declarationMap: false,
|
|
3180
|
-
emitDeclarationOnly: true,
|
|
3181
|
-
skipLibCheck: true
|
|
3182
|
-
},
|
|
3183
|
-
exclude: [
|
|
3184
|
-
"node_modules",
|
|
3185
|
-
"dist"
|
|
3186
|
-
],
|
|
3187
|
-
include: files
|
|
3188
|
-
}, context.config.tsconfigRaw ?? {}));
|
|
3189
|
-
resolvedTsconfig.options.configFilePath = joinPaths$1(context.workspaceConfig.workspaceRoot, context.tsconfig.tsconfigFilePath);
|
|
3190
|
-
resolvedTsconfig.options.pathsBasePath = context.workspaceConfig.workspaceRoot;
|
|
3191
|
-
resolvedTsconfig.options.suppressOutputPathCheck = true;
|
|
3192
|
-
let generatedTypes = await emitTypes(context, resolvedTsconfig, files);
|
|
3193
|
-
context.log(LogLevelLabel.TRACE, `Generating TypeScript declaration file in ${context.config.output.dts}.`);
|
|
3194
|
-
const directives = [];
|
|
3195
|
-
let result = await this.callPreHook(context, "generateTypes", generatedTypes);
|
|
3196
|
-
if (result) {
|
|
3197
|
-
if (isSetObject(result)) {
|
|
3198
|
-
generatedTypes = result.code;
|
|
3199
|
-
if (Array.isArray(result.directives) && result.directives.length > 0) {
|
|
3200
|
-
directives.push(...result.directives);
|
|
3201
|
-
}
|
|
3202
|
-
} else if (isSetString(result)) {
|
|
3203
|
-
generatedTypes = result;
|
|
3204
|
-
}
|
|
3205
|
-
}
|
|
3206
|
-
result = await this.callNormalHook(context, "generateTypes", generatedTypes);
|
|
3207
|
-
if (result) {
|
|
3208
|
-
if (isSetObject(result)) {
|
|
3209
|
-
generatedTypes = result.code;
|
|
3210
|
-
if (Array.isArray(result.directives) && result.directives.length > 0) {
|
|
3211
|
-
directives.push(...result.directives);
|
|
3212
|
-
}
|
|
3213
|
-
} else if (isSetString(result)) {
|
|
3214
|
-
generatedTypes = result;
|
|
3215
|
-
}
|
|
3216
|
-
}
|
|
3217
|
-
result = await this.callPostHook(context, "generateTypes", generatedTypes);
|
|
3218
|
-
if (result) {
|
|
3219
|
-
if (isSetObject(result)) {
|
|
3220
|
-
generatedTypes = result.code;
|
|
3221
|
-
if (Array.isArray(result.directives) && result.directives.length > 0) {
|
|
3222
|
-
directives.push(...result.directives);
|
|
3223
|
-
}
|
|
3224
|
-
} else if (isSetString(result)) {
|
|
3225
|
-
generatedTypes = result;
|
|
3226
|
-
}
|
|
3227
|
-
}
|
|
3228
|
-
await context.fs.writeFile(context.config.output.dts, `${directives ? `${directives.map((directive) => `/// <reference types="${directive}" />`).join("\n")}
|
|
3229
|
-
|
|
3230
|
-
` : ""}${getFileHeader(context, {
|
|
3231
|
-
directive: null,
|
|
3232
|
-
prettierIgnore: false
|
|
3233
|
-
})}
|
|
3234
|
-
|
|
3235
|
-
${formatTypes(generatedTypes)}
|
|
3236
|
-
`, {
|
|
3237
|
-
mode: "fs"
|
|
3238
|
-
});
|
|
3239
|
-
}
|
|
3240
|
-
context.tsconfig = getParsedTypeScriptConfig(context.workspaceConfig.workspaceRoot, context.config.projectRoot, context.config.tsconfig);
|
|
3241
|
-
if (!context.tsconfig) {
|
|
3242
|
-
throw new Error("Failed to parse the TypeScript configuration file.");
|
|
3243
|
-
}
|
|
3244
|
-
await this.callPostHook(context, "prepare");
|
|
3245
|
-
await writeMetaFile(context);
|
|
3246
|
-
context.fs[__VFS_REVERT__]();
|
|
3247
|
-
});
|
|
3248
|
-
this.context.log(LogLevelLabel.INFO, "Powerlines API has been prepared successfully");
|
|
3249
|
-
}
|
|
3250
|
-
/**
|
|
3251
|
-
* Create a new Powerlines project
|
|
3252
|
-
*
|
|
3253
|
-
* @remarks
|
|
3254
|
-
* This method will create a new Powerlines project in the current directory.
|
|
3255
|
-
*
|
|
3256
|
-
* @param inlineConfig - The inline configuration for the new command
|
|
3257
|
-
* @returns A promise that resolves when the project has been created
|
|
3258
|
-
*/
|
|
3259
|
-
async new(inlineConfig) {
|
|
3260
|
-
this.context.log(LogLevelLabel.INFO, "\u{1F195} Creating a new Powerlines project");
|
|
3261
|
-
await this.prepare(inlineConfig);
|
|
3262
|
-
await this.#executeEnvironments(async (context) => {
|
|
3263
|
-
context.log(LogLevelLabel.TRACE, `Initializing the processing options for the Powerlines project.`);
|
|
3264
|
-
await this.callPreHook(context, "new");
|
|
3265
|
-
const files = await listFiles(joinPaths$1(context.powerlinesPath, "files/common/**/*.hbs"));
|
|
3266
|
-
for (const file of files) {
|
|
3267
|
-
context.log(LogLevelLabel.TRACE, `Adding template file: ${file}`);
|
|
3268
|
-
const template = Handlebars.compile(file);
|
|
3269
|
-
await writeFile(context.log, joinPaths$1(context.config.projectRoot, file.replace(".hbs", "")), template(context));
|
|
3270
|
-
}
|
|
3271
|
-
await this.callNormalHook(context, "new");
|
|
3272
|
-
if (context.config.projectType === "application") {
|
|
3273
|
-
const files2 = await listFiles(joinPaths$1(context.powerlinesPath, "files/application/**/*.hbs"));
|
|
3274
|
-
for (const file of files2) {
|
|
3275
|
-
context.log(LogLevelLabel.TRACE, `Adding application template file: ${file}`);
|
|
3276
|
-
const template = Handlebars.compile(file);
|
|
3277
|
-
await writeFile(context.log, joinPaths$1(context.config.projectRoot, file.replace(".hbs", "")), template(context));
|
|
3278
|
-
}
|
|
3279
|
-
} else {
|
|
3280
|
-
const files2 = await listFiles(joinPaths$1(context.powerlinesPath, "files/library/**/*.hbs"));
|
|
3281
|
-
for (const file of files2) {
|
|
3282
|
-
context.log(LogLevelLabel.TRACE, `Adding library template file: ${file}`);
|
|
3283
|
-
const template = Handlebars.compile(file);
|
|
3284
|
-
await writeFile(context.log, joinPaths$1(context.config.projectRoot, file.replace(".hbs", "")), template(context));
|
|
3285
|
-
}
|
|
3286
|
-
}
|
|
3287
|
-
await this.callPostHook(context, "new");
|
|
3288
|
-
});
|
|
3289
|
-
this.context.log(LogLevelLabel.TRACE, "Powerlines - New command completed");
|
|
3290
|
-
}
|
|
3291
|
-
/**
|
|
3292
|
-
* Clean any previously prepared artifacts
|
|
3293
|
-
*
|
|
3294
|
-
* @remarks
|
|
3295
|
-
* This method will remove the previous Powerlines artifacts from the project.
|
|
3296
|
-
*
|
|
3297
|
-
* @param inlineConfig - The inline configuration for the clean command
|
|
3298
|
-
* @returns A promise that resolves when the clean command has completed
|
|
3299
|
-
*/
|
|
3300
|
-
async clean(inlineConfig = {
|
|
3301
|
-
command: "clean"
|
|
3302
|
-
}) {
|
|
3303
|
-
this.context.log(LogLevelLabel.INFO, "\u{1F9F9} Cleaning the previous Powerlines artifacts");
|
|
3304
|
-
await this.prepare(inlineConfig);
|
|
3305
|
-
await this.#executeEnvironments(async (context) => {
|
|
3306
|
-
this.context.log(LogLevelLabel.TRACE, "Cleaning the project's dist and artifacts directories.");
|
|
3307
|
-
await context.fs.rmdir(joinPaths$1(context.workspaceConfig.workspaceRoot, context.config.output.distPath));
|
|
3308
|
-
await context.fs.rmdir(joinPaths$1(context.workspaceConfig.workspaceRoot, context.config.output.artifactsFolder));
|
|
3309
|
-
await callHook(context, "clean", {
|
|
3310
|
-
sequential: true
|
|
3311
|
-
});
|
|
3312
|
-
});
|
|
3313
|
-
this.context.log(LogLevelLabel.TRACE, "Powerlines - Clean command completed");
|
|
3314
|
-
}
|
|
3315
|
-
/**
|
|
3316
|
-
* Lint the project
|
|
3317
|
-
*
|
|
3318
|
-
* @param inlineConfig - The inline configuration for the lint command
|
|
3319
|
-
* @returns A promise that resolves when the lint command has completed
|
|
3320
|
-
*/
|
|
3321
|
-
async lint(inlineConfig = {
|
|
3322
|
-
command: "lint"
|
|
3323
|
-
}) {
|
|
3324
|
-
this.context.log(LogLevelLabel.INFO, "\u{1F4CB} Linting the Powerlines project");
|
|
3325
|
-
await this.prepare(inlineConfig);
|
|
3326
|
-
await this.#executeEnvironments(async (context) => {
|
|
3327
|
-
if (context.config.lint !== false) {
|
|
3328
|
-
await this.callHook(context, "lint");
|
|
3329
|
-
}
|
|
3330
|
-
});
|
|
3331
|
-
this.context.log(LogLevelLabel.TRACE, "Powerlines linting completed");
|
|
3332
|
-
}
|
|
3333
|
-
/**
|
|
3334
|
-
* Build the project
|
|
3335
|
-
*
|
|
3336
|
-
* @remarks
|
|
3337
|
-
* This method will build the Powerlines project, generating the necessary artifacts.
|
|
3338
|
-
*
|
|
3339
|
-
* @param inlineConfig - The inline configuration for the build command
|
|
3340
|
-
* @returns A promise that resolves when the build command has completed
|
|
3341
|
-
*/
|
|
3342
|
-
async build(inlineConfig = {
|
|
3343
|
-
command: "build"
|
|
3344
|
-
}) {
|
|
3345
|
-
this.context.log(LogLevelLabel.INFO, "\u{1F4E6} Building the Powerlines project");
|
|
3346
|
-
await this.prepare(inlineConfig);
|
|
3347
|
-
await this.#executeEnvironments(async (context) => {
|
|
3348
|
-
await this.callPreHook(context, "build");
|
|
3349
|
-
await this.callNormalHook(context, "build");
|
|
3350
|
-
if (context.config.output.distPath !== context.config.output.outputPath) {
|
|
3351
|
-
const sourcePath = appendPath(context.config.output.distPath, context.workspaceConfig.workspaceRoot);
|
|
3352
|
-
const destinationPath = joinPaths$1(appendPath(context.config.output.outputPath, context.workspaceConfig.workspaceRoot), "dist");
|
|
3353
|
-
if (sourcePath !== destinationPath) {
|
|
3354
|
-
context.log(LogLevelLabel.INFO, `Copying build output files from project's build directory (${context.config.output.distPath}) to the workspace's output directory (${context.config.output.outputPath}).`);
|
|
3355
|
-
await copyFiles({
|
|
3356
|
-
input: sourcePath,
|
|
3357
|
-
glob: "**/*"
|
|
3358
|
-
}, destinationPath);
|
|
3359
|
-
}
|
|
3360
|
-
}
|
|
3361
|
-
await Promise.all(context.config.output.assets.map(async (asset) => {
|
|
3362
|
-
context.log(LogLevelLabel.DEBUG, `Copying asset(s): ${chalk4.redBright(context.workspaceConfig.workspaceRoot === asset.input ? asset.glob : joinPaths$1(replacePath(asset.input, context.workspaceConfig.workspaceRoot), asset.glob))} -> ${chalk4.greenBright(joinPaths$1(replacePath(asset.output, context.workspaceConfig.workspaceRoot), asset.glob))} ${Array.isArray(asset.ignore) && asset.ignore.length > 0 ? ` (ignoring: ${asset.ignore.map((i) => chalk4.yellowBright(i)).join(", ")})` : ""}`);
|
|
3363
|
-
await copyFiles(asset, asset.output);
|
|
3364
|
-
}));
|
|
3365
|
-
await this.callPostHook(context, "build");
|
|
3366
|
-
});
|
|
3367
|
-
this.context.log(LogLevelLabel.TRACE, "Powerlines build completed");
|
|
3368
|
-
}
|
|
3369
|
-
/**
|
|
3370
|
-
* Prepare the documentation for the project
|
|
3371
|
-
*
|
|
3372
|
-
* @param inlineConfig - The inline configuration for the docs command
|
|
3373
|
-
* @returns A promise that resolves when the documentation generation has completed
|
|
3374
|
-
*/
|
|
3375
|
-
async docs(inlineConfig = {
|
|
3376
|
-
command: "docs"
|
|
3377
|
-
}) {
|
|
3378
|
-
this.context.log(LogLevelLabel.INFO, "\u{1F4D3} Generating documentation for the Powerlines project");
|
|
3379
|
-
await this.prepare(inlineConfig);
|
|
3380
|
-
await this.#executeEnvironments(async (context) => {
|
|
3381
|
-
context.log(LogLevelLabel.TRACE, "Writing documentation for the Powerlines project artifacts.");
|
|
3382
|
-
await this.prepare(inlineConfig);
|
|
3383
|
-
await this.#executeEnvironments(async (context2) => {
|
|
3384
|
-
await this.callHook(context2, "docs");
|
|
3385
|
-
});
|
|
3386
|
-
});
|
|
3387
|
-
this.#context.log(LogLevelLabel.TRACE, "Powerlines documentation generation completed");
|
|
3388
|
-
}
|
|
3389
|
-
/**
|
|
3390
|
-
* Deploy the project source code
|
|
3391
|
-
*
|
|
3392
|
-
* @remarks
|
|
3393
|
-
* This method will prepare and build the Powerlines project, generating the necessary artifacts for the deployment.
|
|
3394
|
-
*
|
|
3395
|
-
* @param inlineConfig - The inline configuration for the deploy command
|
|
3396
|
-
*/
|
|
3397
|
-
async deploy(inlineConfig = {
|
|
3398
|
-
command: "deploy"
|
|
3399
|
-
}) {
|
|
3400
|
-
this.context.log(LogLevelLabel.INFO, "\u{1F4E6} Deploying the Powerlines project");
|
|
3401
|
-
await this.prepare(inlineConfig);
|
|
3402
|
-
await this.#executeEnvironments(async (context) => {
|
|
3403
|
-
await this.callHook(context, "deploy");
|
|
3404
|
-
});
|
|
3405
|
-
this.context.log(LogLevelLabel.TRACE, "Powerlines deploy completed");
|
|
3406
|
-
}
|
|
3407
|
-
/**
|
|
3408
|
-
* Finalization process
|
|
3409
|
-
*
|
|
3410
|
-
* @remarks
|
|
3411
|
-
* This step includes any final processes or clean up required by Powerlines. It will be run after each Powerlines command.
|
|
3412
|
-
*
|
|
3413
|
-
* @returns A promise that resolves when the finalization process has completed
|
|
3414
|
-
*/
|
|
3415
|
-
async finalize() {
|
|
3416
|
-
this.context.log(LogLevelLabel.TRACE, "Powerlines finalize execution started");
|
|
3417
|
-
await this.#executeEnvironments(async (context) => {
|
|
3418
|
-
await this.callHook(context, "finalize");
|
|
3419
|
-
context.fs[__VFS_REVERT__]();
|
|
3420
|
-
await context.fs.dispose();
|
|
3421
|
-
});
|
|
3422
|
-
this.context.log(LogLevelLabel.TRACE, "Powerlines finalize execution completed");
|
|
3423
|
-
}
|
|
3424
|
-
/**
|
|
3425
|
-
* Calls a hook in parallel
|
|
3426
|
-
*
|
|
3427
|
-
* @param hook - The hook to call
|
|
3428
|
-
* @param options - Options for calling the hook
|
|
3429
|
-
* @param args - The arguments to pass to the hook
|
|
3430
|
-
* @returns The result of the hook call
|
|
3431
|
-
*/
|
|
3432
|
-
async callHookParallel(hook, options, ...args) {
|
|
3433
|
-
return callHook(isSetObject(options?.environment) ? options.environment : await this.#context.getEnvironment(options?.environment), hook, {
|
|
3434
|
-
...options,
|
|
3435
|
-
sequential: false
|
|
3436
|
-
}, ...args);
|
|
3437
|
-
}
|
|
3438
|
-
/**
|
|
3439
|
-
* Calls a hook in sequence
|
|
3440
|
-
*
|
|
3441
|
-
* @param hook - The hook to call
|
|
3442
|
-
* @param options - Options for calling the hook
|
|
3443
|
-
* @param args - The arguments to pass to the hook
|
|
3444
|
-
* @returns The result of the hook call
|
|
3445
|
-
*/
|
|
3446
|
-
async callHookSequential(hook, options, ...args) {
|
|
3447
|
-
return callHook(isSetObject(options?.environment) ? options.environment : await this.#context.getEnvironment(options?.environment), hook, {
|
|
3448
|
-
...options,
|
|
3449
|
-
sequential: true
|
|
3450
|
-
}, ...args);
|
|
3451
|
-
}
|
|
3452
|
-
/**
|
|
3453
|
-
* Calls the `"pre"` ordered hooks in sequence
|
|
3454
|
-
*
|
|
3455
|
-
* @param environment - The environment to use for the hook call
|
|
3456
|
-
* @param hook - The hook to call
|
|
3457
|
-
* @param args - The arguments to pass to the hook
|
|
3458
|
-
* @returns The result of the hook call
|
|
3459
|
-
*/
|
|
3460
|
-
async callPreHook(environment, hook, ...args) {
|
|
3461
|
-
return this.callHookSequential(hook, {
|
|
3462
|
-
order: "pre",
|
|
3463
|
-
environment
|
|
3464
|
-
}, ...args);
|
|
3465
|
-
}
|
|
3466
|
-
/**
|
|
3467
|
-
* Calls the `"post"` ordered hooks in sequence
|
|
3468
|
-
*
|
|
3469
|
-
* @param environment - The environment to use for the hook call
|
|
3470
|
-
* @param hook - The hook to call
|
|
3471
|
-
* @param args - The arguments to pass to the hook
|
|
3472
|
-
* @returns The result of the hook call
|
|
3473
|
-
*/
|
|
3474
|
-
async callPostHook(environment, hook, ...args) {
|
|
3475
|
-
return this.callHookSequential(hook, {
|
|
3476
|
-
order: "post",
|
|
3477
|
-
environment
|
|
3478
|
-
}, ...args);
|
|
3479
|
-
}
|
|
3480
|
-
/**
|
|
3481
|
-
* Calls a hook in sequence
|
|
3482
|
-
*
|
|
3483
|
-
* @param environment - The environment to use for the hook call
|
|
3484
|
-
* @param hook - The hook to call
|
|
3485
|
-
* @param args - The arguments to pass to the hook
|
|
3486
|
-
* @returns The result of the hook call
|
|
3487
|
-
*/
|
|
3488
|
-
async callNormalHook(environment, hook, ...args) {
|
|
3489
|
-
return this.callHookSequential(hook, {
|
|
3490
|
-
order: "normal",
|
|
3491
|
-
environment
|
|
3492
|
-
}, ...args);
|
|
3493
|
-
}
|
|
3494
|
-
/**
|
|
3495
|
-
* Calls the `"pre"` and `"post"` ordered hooks, as well as the normal hooks in sequence
|
|
3496
|
-
*
|
|
3497
|
-
* @param environment - The environment to use for the hook call
|
|
3498
|
-
* @param hook - The hook to call
|
|
3499
|
-
* @param args - The arguments to pass to the hook
|
|
3500
|
-
* @returns The result of the hook call
|
|
3501
|
-
*/
|
|
3502
|
-
async callHook(environment, hook, ...args) {
|
|
3503
|
-
return this.callHookSequential(hook, {
|
|
3504
|
-
environment
|
|
3505
|
-
}, ...args);
|
|
3506
|
-
}
|
|
3507
|
-
async [Symbol.asyncDispose]() {
|
|
3508
|
-
await this.finalize();
|
|
3509
|
-
}
|
|
3510
|
-
/**
|
|
3511
|
-
* Get the configured environments
|
|
3512
|
-
*
|
|
3513
|
-
* @returns The configured environments
|
|
3514
|
-
*/
|
|
3515
|
-
async #getEnvironments() {
|
|
3516
|
-
if (!this.context.config.environments || Object.keys(this.context.config.environments).length <= 1) {
|
|
3517
|
-
this.context.log(LogLevelLabel.DEBUG, "No environments are configured for this Powerlines project. Using the default environment.");
|
|
3518
|
-
return [
|
|
3519
|
-
await this.context.getEnvironment()
|
|
3520
|
-
];
|
|
3521
|
-
}
|
|
3522
|
-
this.context.log(LogLevelLabel.DEBUG, `Found ${Object.keys(this.context.config.environments).length} configured environment(s) for this Powerlines project.`);
|
|
3523
|
-
return (await Promise.all(Object.entries(this.context.config.environments).map(async ([name, config]) => {
|
|
3524
|
-
const environment = await this.context.getEnvironmentSafe(name);
|
|
3525
|
-
if (!environment) {
|
|
3526
|
-
const resolvedEnvironment = await this.callHookParallel("configEnvironment", {
|
|
3527
|
-
environment: name
|
|
3528
|
-
}, name, config);
|
|
3529
|
-
if (resolvedEnvironment) {
|
|
3530
|
-
this.context.environments[name] = await this.context.in(resolvedEnvironment);
|
|
3531
|
-
}
|
|
3532
|
-
}
|
|
3533
|
-
return this.context.environments[name];
|
|
3534
|
-
}))).filter((context) => isSet(context));
|
|
3535
|
-
}
|
|
3536
|
-
/**
|
|
3537
|
-
* Execute a handler function for each environment
|
|
3538
|
-
*
|
|
3539
|
-
* @param handle - The handler function to execute for each environment
|
|
3540
|
-
*/
|
|
3541
|
-
async #executeEnvironments(handle) {
|
|
3542
|
-
await Promise.all((await this.#getEnvironments()).map(async (context) => {
|
|
3543
|
-
return Promise.resolve(handle(context));
|
|
3544
|
-
}));
|
|
3545
|
-
}
|
|
3546
|
-
/**
|
|
3547
|
-
* Add a Powerlines plugin used in the build process
|
|
3548
|
-
*
|
|
3549
|
-
* @param config - The import path of the plugin to add
|
|
3550
|
-
*/
|
|
3551
|
-
async #addPlugin(config) {
|
|
3552
|
-
if (config) {
|
|
3553
|
-
const plugin = await this.#initPlugin(config);
|
|
3554
|
-
if (!plugin) {
|
|
3555
|
-
return;
|
|
3556
|
-
}
|
|
3557
|
-
if (plugin.dependsOn) {
|
|
3558
|
-
for (const required of plugin.dependsOn) {
|
|
3559
|
-
await this.#addPlugin(required);
|
|
3560
|
-
}
|
|
3561
|
-
}
|
|
3562
|
-
this.context.log(LogLevelLabel.DEBUG, `Successfully initialized the ${chalk4.bold.cyanBright(plugin.name)} plugin`);
|
|
3563
|
-
await this.context.addPlugin(plugin);
|
|
3564
|
-
}
|
|
3565
|
-
}
|
|
3566
|
-
/**
|
|
3567
|
-
* Initialize a Powerlines plugin
|
|
3568
|
-
*
|
|
3569
|
-
* @param config - The configuration for the plugin
|
|
3570
|
-
* @returns The initialized plugin instance, or null if the plugin was a duplicate
|
|
3571
|
-
* @throws Will throw an error if the plugin cannot be found or is invalid
|
|
3572
|
-
*/
|
|
3573
|
-
async #initPlugin(config) {
|
|
3574
|
-
let awaited = config;
|
|
3575
|
-
if (isPromiseLike(config)) {
|
|
3576
|
-
awaited = await Promise.resolve(config);
|
|
3577
|
-
}
|
|
3578
|
-
if (!isPluginConfig(awaited)) {
|
|
3579
|
-
throw new Error(`Invalid plugin specified in the configuration - ${JSON.stringify(awaited)}. Please ensure the value is a plugin name, an object with the \`plugin\` and \`props\` properties, or an instance of \`Plugin\`.`);
|
|
3580
|
-
}
|
|
3581
|
-
let plugin;
|
|
3582
|
-
if (isPlugin(awaited)) {
|
|
3583
|
-
plugin = awaited;
|
|
3584
|
-
} else if (isFunction(awaited)) {
|
|
3585
|
-
plugin = await Promise.resolve(awaited());
|
|
3586
|
-
} else if (isSetString(awaited)) {
|
|
3587
|
-
const resolved = await this.#resolvePlugin(awaited);
|
|
3588
|
-
if (isFunction(resolved)) {
|
|
3589
|
-
plugin = await Promise.resolve(resolved());
|
|
3590
|
-
} else {
|
|
3591
|
-
plugin = resolved;
|
|
3592
|
-
}
|
|
3593
|
-
} else if (isPluginConfigTuple(awaited) || isPluginConfigObject(awaited)) {
|
|
3594
|
-
let pluginConfig;
|
|
3595
|
-
let pluginOptions;
|
|
3596
|
-
if (isPluginConfigTuple(awaited)) {
|
|
3597
|
-
pluginConfig = awaited[0];
|
|
3598
|
-
pluginOptions = awaited?.length === 2 ? awaited[1] : void 0;
|
|
3599
|
-
} else {
|
|
3600
|
-
pluginConfig = awaited.plugin;
|
|
3601
|
-
pluginOptions = awaited.options;
|
|
3602
|
-
}
|
|
3603
|
-
if (isSetString(pluginConfig)) {
|
|
3604
|
-
const resolved = await this.#resolvePlugin(pluginConfig);
|
|
3605
|
-
if (isFunction(resolved)) {
|
|
3606
|
-
plugin = await Promise.resolve(pluginOptions ? resolved(pluginOptions) : resolved());
|
|
3607
|
-
} else {
|
|
3608
|
-
plugin = resolved;
|
|
3609
|
-
}
|
|
3610
|
-
} else if (isFunction(pluginConfig)) {
|
|
3611
|
-
plugin = await Promise.resolve(pluginConfig(pluginOptions));
|
|
3612
|
-
} else if (isPlugin(pluginConfig)) {
|
|
3613
|
-
plugin = pluginConfig;
|
|
3614
|
-
}
|
|
3615
|
-
}
|
|
3616
|
-
if (!plugin) {
|
|
3617
|
-
throw new Error(`The plugin configuration ${JSON.stringify(awaited)} is invalid. This configuration must point to a valid Powerlines plugin module.`);
|
|
3618
|
-
}
|
|
3619
|
-
if (!isPlugin(plugin)) {
|
|
3620
|
-
throw new Error(`The plugin option ${JSON.stringify(plugin)} does not export a valid module. This configuration must point to a valid Powerlines plugin module.`);
|
|
3621
|
-
}
|
|
3622
|
-
if (checkDedupe(plugin, this.context.plugins)) {
|
|
3623
|
-
this.context.log(LogLevelLabel.TRACE, `Duplicate ${chalk4.bold.cyanBright(plugin.name)} plugin dependency detected - Skipping initialization.`);
|
|
3624
|
-
return null;
|
|
3625
|
-
}
|
|
3626
|
-
this.context.log(LogLevelLabel.TRACE, `Initializing the ${chalk4.bold.cyanBright(plugin.name)} plugin...`);
|
|
3627
|
-
return plugin;
|
|
3628
|
-
}
|
|
3629
|
-
async #resolvePlugin(pluginPath) {
|
|
3630
|
-
if (pluginPath.startsWith("@") && pluginPath.split("/").filter(Boolean).length > 2) {
|
|
3631
|
-
const splits = pluginPath.split("/").filter(Boolean);
|
|
3632
|
-
pluginPath = `${splits[0]}/${splits[1]}`;
|
|
3633
|
-
}
|
|
3634
|
-
const isInstalled = isPackageExists(pluginPath, {
|
|
3635
|
-
paths: [
|
|
3636
|
-
this.context.workspaceConfig.workspaceRoot,
|
|
3637
|
-
this.context.config.projectRoot
|
|
3638
|
-
]
|
|
3639
|
-
});
|
|
3640
|
-
if (!isInstalled && this.context.config.skipInstalls !== true) {
|
|
3641
|
-
this.#context.log(LogLevelLabel.WARN, `The plugin package "${pluginPath}" is not installed. It will be installed automatically.`);
|
|
3642
|
-
const result = await install(pluginPath, {
|
|
3643
|
-
cwd: this.context.config.projectRoot
|
|
3644
|
-
});
|
|
3645
|
-
if (isNumber(result.exitCode) && result.exitCode > 0) {
|
|
3646
|
-
this.#context.log(LogLevelLabel.ERROR, result.stderr);
|
|
3647
|
-
throw new Error(`An error occurred while installing the build plugin package "${pluginPath}" `);
|
|
3648
|
-
}
|
|
3649
|
-
}
|
|
3650
|
-
try {
|
|
3651
|
-
const module = await this.context.resolver.plugin.import(this.context.resolver.plugin.esmResolve(joinPaths$1(pluginPath, "plugin")));
|
|
3652
|
-
const result = module.plugin ?? module.default;
|
|
3653
|
-
if (!result) {
|
|
3654
|
-
throw new Error(`The plugin package "${pluginPath}" does not export a valid module.`);
|
|
3655
|
-
}
|
|
3656
|
-
return result;
|
|
3657
|
-
} catch (error) {
|
|
3658
|
-
try {
|
|
3659
|
-
const module = await this.context.resolver.plugin.import(this.context.resolver.plugin.esmResolve(pluginPath));
|
|
3660
|
-
const result = module.plugin ?? module.default;
|
|
3661
|
-
if (!result) {
|
|
3662
|
-
throw new Error(`The plugin package "${pluginPath}" does not export a valid module.`);
|
|
3663
|
-
}
|
|
3664
|
-
return result;
|
|
3665
|
-
} catch {
|
|
3666
|
-
if (!isInstalled) {
|
|
3667
|
-
throw new Error(`The plugin package "${pluginPath}" is not installed. Please install the package using the command: "npm install ${pluginPath} --save-dev"`);
|
|
3668
|
-
} else {
|
|
3669
|
-
throw new Error(`An error occurred while importing the build plugin package "${pluginPath}":
|
|
3670
|
-
${isError(error) ? error.message : String(error)}
|
|
3671
|
-
|
|
3672
|
-
Note: Please ensure the plugin package's default export is a class that extends \`Plugin\` with a constructor that excepts a single arguments of type \`PluginOptions\`.`);
|
|
3673
|
-
}
|
|
3674
|
-
}
|
|
3675
|
-
}
|
|
3676
|
-
}
|
|
3677
|
-
};
|
|
3678
|
-
|
|
3679
|
-
// src/lib/unplugin/factory.ts
|
|
3680
|
-
function createUnpluginFactory(variant, decorate) {
|
|
3681
|
-
return (config, meta) => {
|
|
3682
|
-
const log = createLog("unplugin", config);
|
|
3683
|
-
log(LogLevelLabel.DEBUG, "Initializing Unplugin");
|
|
3684
|
-
try {
|
|
3685
|
-
const userConfig = {
|
|
3686
|
-
...config,
|
|
3687
|
-
variant,
|
|
3688
|
-
unplugin: meta
|
|
3689
|
-
};
|
|
3690
|
-
let api;
|
|
3691
|
-
let resolvePatterns = [];
|
|
3692
|
-
async function buildStart() {
|
|
3693
|
-
log(LogLevelLabel.DEBUG, "Powerlines build plugin starting...");
|
|
3694
|
-
const workspaceRoot = getWorkspaceRoot(process.cwd());
|
|
3695
|
-
api = await PowerlinesAPI.from(workspaceRoot, userConfig);
|
|
3696
|
-
if (api.context.config.build.skipNodeModulesBundle) {
|
|
3697
|
-
resolvePatterns = tsconfigPathsToRegExp(api.context.tsconfig.options.paths ?? []);
|
|
3698
|
-
}
|
|
3699
|
-
log(LogLevelLabel.DEBUG, "Preparing build artifacts for the Powerlines project...");
|
|
3700
|
-
await api.prepare({
|
|
3701
|
-
command: "build"
|
|
3702
|
-
});
|
|
3703
|
-
}
|
|
3704
|
-
__name(buildStart, "buildStart");
|
|
3705
|
-
async function resolveId(id, importer, options = {
|
|
3706
|
-
isEntry: false
|
|
3707
|
-
}) {
|
|
3708
|
-
return handleResolveId(api.context, {
|
|
3709
|
-
id,
|
|
3710
|
-
importer,
|
|
3711
|
-
options
|
|
3712
|
-
}, {
|
|
3713
|
-
skipNodeModulesBundle: api.context.config.build.skipNodeModulesBundle,
|
|
3714
|
-
external: api.context.config.build.external,
|
|
3715
|
-
noExternal: api.context.config.build.noExternal,
|
|
3716
|
-
resolvePatterns
|
|
3717
|
-
});
|
|
3718
|
-
}
|
|
3719
|
-
__name(resolveId, "resolveId");
|
|
3720
|
-
async function load(id) {
|
|
3721
|
-
const environment = await api.context.getEnvironment();
|
|
3722
|
-
if (id) {
|
|
3723
|
-
const resolvedPath = environment.fs.resolve(id);
|
|
3724
|
-
if (resolvedPath) {
|
|
3725
|
-
return environment.fs.readFile(resolvedPath);
|
|
3726
|
-
}
|
|
3727
|
-
}
|
|
3728
|
-
let result2 = await api.callPreHook(environment, "load", id);
|
|
3729
|
-
if (result2) {
|
|
3730
|
-
return result2;
|
|
3731
|
-
}
|
|
3732
|
-
result2 = await api.callNormalHook(environment, "load", id);
|
|
3733
|
-
if (result2) {
|
|
3734
|
-
return result2;
|
|
3735
|
-
}
|
|
3736
|
-
return api.callPostHook(environment, "load", id);
|
|
3737
|
-
}
|
|
3738
|
-
__name(load, "load");
|
|
3739
|
-
async function transform(code, id) {
|
|
3740
|
-
const environment = await api.context.getEnvironment();
|
|
3741
|
-
let transformed = code;
|
|
3742
|
-
let result2 = await api.callPreHook(environment, "transform", getString(transformed), id);
|
|
3743
|
-
if (result2) {
|
|
3744
|
-
transformed = result2;
|
|
3745
|
-
}
|
|
3746
|
-
result2 = await api.callNormalHook(environment, "transform", getString(transformed), id);
|
|
3747
|
-
if (result2) {
|
|
3748
|
-
transformed = result2;
|
|
3749
|
-
}
|
|
3750
|
-
result2 = await api.callPostHook(environment, "transform", getString(transformed), id);
|
|
3751
|
-
if (result2) {
|
|
3752
|
-
transformed = result2;
|
|
3753
|
-
}
|
|
3754
|
-
return transformed;
|
|
3755
|
-
}
|
|
3756
|
-
__name(transform, "transform");
|
|
3757
|
-
async function writeBundle() {
|
|
3758
|
-
log(LogLevelLabel.DEBUG, "Finalizing Powerlines project output...");
|
|
3759
|
-
const environment = await api.context.getEnvironment();
|
|
3760
|
-
await api.callHook(environment, "writeBundle");
|
|
3761
|
-
}
|
|
3762
|
-
__name(writeBundle, "writeBundle");
|
|
3763
|
-
const result = {
|
|
3764
|
-
name: "powerlines",
|
|
3765
|
-
resolveId: {
|
|
3766
|
-
filter: {
|
|
3767
|
-
id: {
|
|
3768
|
-
include: [
|
|
3769
|
-
/.*/
|
|
3770
|
-
]
|
|
3771
|
-
}
|
|
3772
|
-
},
|
|
3773
|
-
handler: resolveId
|
|
3774
|
-
},
|
|
3775
|
-
load: {
|
|
3776
|
-
filter: {
|
|
3777
|
-
id: {
|
|
3778
|
-
include: [
|
|
3779
|
-
/.*/,
|
|
3780
|
-
/^storm:/
|
|
3781
|
-
]
|
|
3782
|
-
}
|
|
3783
|
-
},
|
|
3784
|
-
handler: load
|
|
3785
|
-
},
|
|
3786
|
-
transform,
|
|
3787
|
-
buildStart,
|
|
3788
|
-
writeBundle
|
|
3789
|
-
};
|
|
3790
|
-
return decorate ? decorate(api, result) : result;
|
|
3791
|
-
} catch (error) {
|
|
3792
|
-
log(LogLevelLabel.FATAL, error?.message);
|
|
3793
|
-
throw error;
|
|
3794
|
-
}
|
|
3795
|
-
};
|
|
3796
|
-
}
|
|
3797
|
-
__name(createUnpluginFactory, "createUnpluginFactory");
|
|
3798
|
-
|
|
3799
|
-
export { VirtualFileSystem, createUnpluginFactory };
|
|
2506
|
+
export { PowerlinesContext, VirtualFileSystem, __VFS_PATCH__, __VFS_REVERT__, addPluginHook, checkDedupe, getHookHandler, isHookExternal, isPlugin, isPluginConfig, isPluginConfigObject, isPluginConfigTuple, isPluginHook };
|