@powerlines/core 0.15.0 → 0.15.1
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/constants/api.cjs +6 -5
- package/dist/constants/api.d.cts +3 -3
- package/dist/constants/api.d.cts.map +1 -1
- package/dist/constants/api.d.mts +3 -3
- package/dist/constants/api.d.mts.map +1 -1
- package/dist/constants/api.mjs +4 -4
- package/dist/constants/api.mjs.map +1 -1
- package/dist/constants/commands.cjs +3 -2
- package/dist/constants/commands.d.cts +1 -1
- package/dist/constants/commands.d.mts +1 -1
- package/dist/constants/commands.mjs +2 -2
- package/dist/constants/commands.mjs.map +1 -1
- package/dist/constants/devtools.cjs +23 -0
- package/dist/constants/devtools.d.cts +13 -0
- package/dist/constants/devtools.d.cts.map +1 -0
- package/dist/constants/devtools.d.mts +13 -0
- package/dist/constants/devtools.d.mts.map +1 -0
- package/dist/constants/devtools.mjs +14 -0
- package/dist/constants/devtools.mjs.map +1 -0
- package/dist/constants/environments.cjs +1 -0
- package/dist/constants/extensions.cjs +21 -0
- package/dist/constants/extensions.d.cts +5 -0
- package/dist/constants/extensions.d.cts.map +1 -0
- package/dist/constants/extensions.d.mts +5 -0
- package/dist/constants/extensions.d.mts.map +1 -0
- package/dist/constants/extensions.mjs +20 -0
- package/dist/constants/extensions.mjs.map +1 -0
- package/dist/constants/fs.cjs +1 -0
- package/dist/constants/hooks.cjs +1 -0
- package/dist/constants/index.cjs +48 -30
- package/dist/constants/index.d.cts +5 -3
- package/dist/constants/index.d.mts +5 -3
- package/dist/constants/index.mjs +5 -3
- package/dist/constants/log-level.cjs +90 -0
- package/dist/constants/log-level.d.cts +63 -0
- package/dist/constants/log-level.d.cts.map +1 -0
- package/dist/constants/log-level.d.mts +63 -0
- package/dist/constants/log-level.d.mts.map +1 -0
- package/dist/constants/log-level.mjs +82 -0
- package/dist/constants/log-level.mjs.map +1 -0
- package/dist/constants/meta.cjs +1 -0
- package/dist/constants/plugin.cjs +3 -2
- package/dist/constants/plugin.d.cts +2 -2
- package/dist/constants/plugin.d.mts +2 -2
- package/dist/context/base-context.cjs +127 -0
- package/dist/context/base-context.d.cts +81 -0
- package/dist/context/base-context.d.cts.map +1 -0
- package/dist/context/base-context.d.mts +81 -0
- package/dist/context/base-context.d.mts.map +1 -0
- package/dist/context/base-context.mjs +125 -0
- package/dist/context/base-context.mjs.map +1 -0
- package/dist/context/context.cjs +934 -0
- package/dist/context/context.d.cts +369 -0
- package/dist/context/context.d.cts.map +1 -0
- package/dist/context/context.d.mts +369 -0
- package/dist/context/context.d.mts.map +1 -0
- package/dist/context/context.mjs +932 -0
- package/dist/context/context.mjs.map +1 -0
- package/dist/context/environment-context.cjs +219 -0
- package/dist/context/environment-context.d.cts +100 -0
- package/dist/context/environment-context.d.cts.map +1 -0
- package/dist/context/environment-context.d.mts +100 -0
- package/dist/context/environment-context.d.mts.map +1 -0
- package/dist/context/environment-context.mjs +218 -0
- package/dist/context/environment-context.mjs.map +1 -0
- package/dist/context/execution-context.cjs +230 -0
- package/dist/context/execution-context.d.cts +101 -0
- package/dist/context/execution-context.d.cts.map +1 -0
- package/dist/context/execution-context.d.mts +101 -0
- package/dist/context/execution-context.d.mts.map +1 -0
- package/dist/context/execution-context.mjs +228 -0
- package/dist/context/execution-context.mjs.map +1 -0
- package/dist/context/index.cjs +12 -0
- package/dist/context/index.d.cts +6 -0
- package/dist/context/index.d.mts +6 -0
- package/dist/context/index.mjs +7 -0
- package/dist/context/plugin-context.cjs +83 -0
- package/dist/context/plugin-context.d.cts +18 -0
- package/dist/context/plugin-context.d.cts.map +1 -0
- package/dist/context/plugin-context.d.mts +18 -0
- package/dist/context/plugin-context.d.mts.map +1 -0
- package/dist/context/plugin-context.mjs +82 -0
- package/dist/context/plugin-context.mjs.map +1 -0
- package/dist/index.cjs +62 -9
- package/dist/index.d.cts +20 -9
- package/dist/index.d.mts +20 -9
- package/dist/index.mjs +17 -5
- package/dist/lib/config.cjs +160 -15
- package/dist/lib/config.d.cts +92 -6
- package/dist/lib/config.d.cts.map +1 -1
- package/dist/lib/config.d.mts +92 -6
- package/dist/lib/config.d.mts.map +1 -1
- package/dist/lib/config.mjs +154 -16
- package/dist/lib/config.mjs.map +1 -1
- package/dist/lib/context-helpers.cjs +43 -0
- package/dist/lib/context-helpers.d.cts +19 -0
- package/dist/lib/context-helpers.d.cts.map +1 -0
- package/dist/lib/context-helpers.d.mts +19 -0
- package/dist/lib/context-helpers.d.mts.map +1 -0
- package/dist/lib/context-helpers.mjs +41 -0
- package/dist/lib/context-helpers.mjs.map +1 -0
- package/dist/lib/entry.cjs +5 -5
- package/dist/lib/entry.d.cts.map +1 -1
- package/dist/lib/entry.d.mts.map +1 -1
- package/dist/lib/entry.mjs +5 -5
- package/dist/lib/entry.mjs.map +1 -1
- package/dist/lib/environment.cjs +72 -0
- package/dist/lib/environment.d.cts +12 -0
- package/dist/lib/environment.d.cts.map +1 -0
- package/dist/lib/environment.d.mts +12 -0
- package/dist/lib/environment.d.mts.map +1 -0
- package/dist/lib/environment.mjs +67 -0
- package/dist/lib/environment.mjs.map +1 -0
- package/dist/lib/events.cjs +43 -0
- package/dist/lib/events.d.cts +10 -0
- package/dist/lib/events.d.cts.map +1 -0
- package/dist/lib/events.d.mts +10 -0
- package/dist/lib/events.d.mts.map +1 -0
- package/dist/lib/events.mjs +42 -0
- package/dist/lib/events.mjs.map +1 -0
- package/dist/lib/generate-types.cjs +371 -0
- package/dist/lib/generate-types.d.cts +67 -0
- package/dist/lib/generate-types.d.cts.map +1 -0
- package/dist/lib/generate-types.d.mts +67 -0
- package/dist/lib/generate-types.d.mts.map +1 -0
- package/dist/lib/generate-types.mjs +368 -0
- package/dist/lib/generate-types.mjs.map +1 -0
- package/dist/lib/hooks.cjs +152 -0
- package/dist/lib/hooks.d.cts +28 -0
- package/dist/lib/hooks.d.cts.map +1 -0
- package/dist/lib/hooks.d.mts +28 -0
- package/dist/lib/hooks.d.mts.map +1 -0
- package/dist/lib/hooks.mjs +147 -0
- package/dist/lib/hooks.mjs.map +1 -0
- package/dist/lib/index.cjs +64 -9
- package/dist/lib/index.d.cts +15 -3
- package/dist/lib/index.d.mts +15 -3
- package/dist/lib/index.mjs +19 -5
- package/dist/lib/install-dependencies.cjs +25 -0
- package/dist/lib/install-dependencies.d.cts +12 -0
- package/dist/lib/install-dependencies.d.cts.map +1 -0
- package/dist/lib/install-dependencies.d.mts +12 -0
- package/dist/lib/install-dependencies.d.mts.map +1 -0
- package/dist/lib/install-dependencies.mjs +24 -0
- package/dist/lib/install-dependencies.mjs.map +1 -0
- package/dist/lib/meta.cjs +57 -0
- package/dist/lib/meta.d.cts +34 -0
- package/dist/lib/meta.d.cts.map +1 -0
- package/dist/lib/meta.d.mts +34 -0
- package/dist/lib/meta.d.mts.map +1 -0
- package/dist/lib/meta.mjs +54 -0
- package/dist/lib/meta.mjs.map +1 -0
- package/dist/lib/plugins.cjs +150 -0
- package/dist/lib/plugins.d.cts +40 -0
- package/dist/lib/plugins.d.cts.map +1 -0
- package/dist/lib/plugins.d.mts +40 -0
- package/dist/lib/plugins.d.mts.map +1 -0
- package/dist/lib/plugins.mjs +146 -0
- package/dist/lib/plugins.mjs.map +1 -0
- package/dist/lib/resolver.cjs +35 -0
- package/dist/lib/resolver.d.cts +21 -0
- package/dist/lib/resolver.d.cts.map +1 -0
- package/dist/lib/resolver.d.mts +21 -0
- package/dist/lib/resolver.d.mts.map +1 -0
- package/dist/lib/resolver.mjs +33 -0
- package/dist/lib/resolver.mjs.map +1 -0
- package/dist/lib/schemas.cjs +9 -0
- package/dist/lib/schemas.d.cts +2 -0
- package/dist/lib/schemas.d.mts +2 -0
- package/dist/lib/schemas.mjs +3 -0
- package/dist/lib/streaming-channel.cjs +260 -0
- package/dist/lib/streaming-channel.d.cts +133 -0
- package/dist/lib/streaming-channel.d.cts.map +1 -0
- package/dist/lib/streaming-channel.d.mts +133 -0
- package/dist/lib/streaming-channel.d.mts.map +1 -0
- package/dist/lib/streaming-channel.mjs +258 -0
- package/dist/lib/streaming-channel.mjs.map +1 -0
- package/dist/lib/typescript/index.cjs +16 -0
- package/dist/lib/typescript/index.d.cts +3 -0
- package/dist/lib/typescript/index.d.mts +3 -0
- package/dist/lib/typescript/index.mjs +4 -0
- package/dist/lib/typescript/ts-morph.cjs +105 -0
- package/dist/lib/typescript/ts-morph.d.cts +38 -0
- package/dist/lib/typescript/ts-morph.d.cts.map +1 -0
- package/dist/lib/typescript/ts-morph.d.mts +38 -0
- package/dist/lib/typescript/ts-morph.d.mts.map +1 -0
- package/dist/lib/typescript/ts-morph.mjs +102 -0
- package/dist/lib/typescript/ts-morph.mjs.map +1 -0
- package/dist/lib/typescript/tsconfig.cjs +253 -0
- package/dist/lib/typescript/tsconfig.d.cts +77 -0
- package/dist/lib/typescript/tsconfig.d.cts.map +1 -0
- package/dist/lib/typescript/tsconfig.d.mts +77 -0
- package/dist/lib/typescript/tsconfig.d.mts.map +1 -0
- package/dist/lib/typescript/tsconfig.mjs +240 -0
- package/dist/lib/typescript/tsconfig.mjs.map +1 -0
- package/dist/lib/unplugin/helpers.cjs +2 -2
- package/dist/lib/unplugin/module-resolution.cjs +18 -18
- package/dist/lib/unplugin/module-resolution.mjs +18 -18
- package/dist/lib/unplugin/module-resolution.mjs.map +1 -1
- package/dist/lib/unplugin/plugin.cjs +55 -62
- package/dist/lib/unplugin/plugin.d.cts +10 -11
- package/dist/lib/unplugin/plugin.d.cts.map +1 -1
- package/dist/lib/unplugin/plugin.d.mts +10 -11
- package/dist/lib/unplugin/plugin.d.mts.map +1 -1
- package/dist/lib/unplugin/plugin.mjs +55 -62
- package/dist/lib/unplugin/plugin.mjs.map +1 -1
- package/dist/lib/utilities/file-header.cjs +2 -2
- package/dist/lib/utilities/file-header.mjs +2 -2
- package/dist/lib/utilities/file-header.mjs.map +1 -1
- package/dist/lib/utilities/format.cjs +1 -1
- package/dist/lib/utilities/format.mjs +1 -1
- package/dist/lib/utilities/index.cjs +2 -2
- package/dist/lib/utilities/index.mjs +2 -2
- package/dist/lib/utilities/write-file.cjs +1 -2
- package/dist/lib/utilities/write-file.d.cts +1 -1
- package/dist/lib/utilities/write-file.d.cts.map +1 -1
- package/dist/lib/utilities/write-file.d.mts +1 -1
- package/dist/lib/utilities/write-file.d.mts.map +1 -1
- package/dist/lib/utilities/write-file.mjs +1 -2
- package/dist/lib/utilities/write-file.mjs.map +1 -1
- package/dist/lib/vfs.cjs +1104 -0
- package/dist/lib/vfs.d.cts +321 -0
- package/dist/lib/vfs.d.cts.map +1 -0
- package/dist/lib/vfs.d.mts +321 -0
- package/dist/lib/vfs.d.mts.map +1 -0
- package/dist/lib/vfs.mjs +1102 -0
- package/dist/lib/vfs.mjs.map +1 -0
- package/dist/plugin-base.cjs +1 -1
- package/dist/plugin-base.mjs +1 -1
- package/dist/plugin-base.mjs.map +1 -1
- package/dist/plugin-utils/build-helpers.cjs +2 -2
- package/dist/plugin-utils/build-helpers.mjs +2 -2
- package/dist/plugin-utils/build-helpers.mjs.map +1 -1
- package/dist/plugin-utils/context-helpers.cjs +22 -12
- package/dist/plugin-utils/context-helpers.d.cts +9 -1
- package/dist/plugin-utils/context-helpers.d.cts.map +1 -1
- package/dist/plugin-utils/context-helpers.d.mts +9 -1
- package/dist/plugin-utils/context-helpers.d.mts.map +1 -1
- package/dist/plugin-utils/context-helpers.mjs +22 -13
- package/dist/plugin-utils/context-helpers.mjs.map +1 -1
- package/dist/plugin-utils/filter.cjs +13 -5
- package/dist/plugin-utils/filter.d.cts +2 -1
- package/dist/plugin-utils/filter.d.cts.map +1 -1
- package/dist/plugin-utils/filter.d.mts +2 -1
- package/dist/plugin-utils/filter.d.mts.map +1 -1
- package/dist/plugin-utils/filter.mjs +13 -6
- package/dist/plugin-utils/filter.mjs.map +1 -1
- package/dist/plugin-utils/format.cjs +44 -0
- package/dist/plugin-utils/format.d.cts +11 -0
- package/dist/plugin-utils/format.d.cts.map +1 -0
- package/dist/plugin-utils/format.d.mts +11 -0
- package/dist/plugin-utils/format.d.mts.map +1 -0
- package/dist/plugin-utils/format.mjs +43 -0
- package/dist/plugin-utils/format.mjs.map +1 -0
- package/dist/plugin-utils/helpers.cjs +6 -6
- package/dist/plugin-utils/helpers.d.cts +15 -15
- package/dist/plugin-utils/helpers.d.cts.map +1 -1
- package/dist/plugin-utils/helpers.d.mts +15 -15
- package/dist/plugin-utils/helpers.d.mts.map +1 -1
- package/dist/plugin-utils/helpers.mjs +1 -1
- package/dist/plugin-utils/helpers.mjs.map +1 -1
- package/dist/plugin-utils/index.cjs +34 -4
- package/dist/plugin-utils/index.d.cts +7 -4
- package/dist/plugin-utils/index.d.mts +7 -4
- package/dist/plugin-utils/index.mjs +9 -6
- package/dist/plugin-utils/install.cjs +47 -0
- package/dist/plugin-utils/install.d.cts +23 -0
- package/dist/plugin-utils/install.d.cts.map +1 -0
- package/dist/plugin-utils/install.d.mts +23 -0
- package/dist/plugin-utils/install.d.mts.map +1 -0
- package/dist/plugin-utils/install.mjs +45 -0
- package/dist/plugin-utils/install.mjs.map +1 -0
- package/dist/plugin-utils/logging.cjs +588 -1
- package/dist/plugin-utils/logging.d.cts +93 -1
- package/dist/plugin-utils/logging.d.cts.map +1 -1
- package/dist/plugin-utils/logging.d.mts +93 -1
- package/dist/plugin-utils/logging.d.mts.map +1 -1
- package/dist/plugin-utils/logging.mjs +572 -1
- package/dist/plugin-utils/logging.mjs.map +1 -1
- package/dist/plugin-utils/merge.cjs +1 -1
- package/dist/plugin-utils/merge.mjs +1 -1
- package/dist/plugin-utils/modules.cjs +1 -1
- package/dist/plugin-utils/modules.mjs +1 -1
- package/dist/plugin-utils/modules.mjs.map +1 -1
- package/dist/plugin-utils/paths.cjs +6 -2
- package/dist/plugin-utils/paths.mjs +6 -2
- package/dist/plugin-utils/paths.mjs.map +1 -1
- package/dist/plugin-utils/virtual.cjs +80 -0
- package/dist/plugin-utils/virtual.d.cts +69 -0
- package/dist/plugin-utils/virtual.d.cts.map +1 -0
- package/dist/plugin-utils/virtual.d.mts +69 -0
- package/dist/plugin-utils/virtual.d.mts.map +1 -0
- package/dist/plugin-utils/virtual.mjs +73 -0
- package/dist/plugin-utils/virtual.mjs.map +1 -0
- package/dist/schemas/fs.cjs +232 -0
- package/dist/schemas/fs.d.cts +127 -0
- package/dist/schemas/fs.d.cts.map +1 -0
- package/dist/schemas/fs.d.mts +127 -0
- package/dist/schemas/fs.d.mts.map +1 -0
- package/dist/schemas/fs.mjs +226 -0
- package/dist/schemas/fs.mjs.map +1 -0
- package/dist/storage/base.cjs +216 -0
- package/dist/storage/base.d.cts +201 -0
- package/dist/storage/base.d.cts.map +1 -0
- package/dist/storage/base.d.mts +201 -0
- package/dist/storage/base.d.mts.map +1 -0
- package/dist/storage/base.mjs +215 -0
- package/dist/storage/base.mjs.map +1 -0
- package/dist/storage/file-system.cjs +180 -0
- package/dist/storage/file-system.d.cts +129 -0
- package/dist/storage/file-system.d.cts.map +1 -0
- package/dist/storage/file-system.d.mts +129 -0
- package/dist/storage/file-system.d.mts.map +1 -0
- package/dist/storage/file-system.mjs +179 -0
- package/dist/storage/file-system.mjs.map +1 -0
- package/dist/storage/helpers.cjs +37 -0
- package/dist/storage/helpers.d.cts +25 -0
- package/dist/storage/helpers.d.cts.map +1 -0
- package/dist/storage/helpers.d.mts +25 -0
- package/dist/storage/helpers.d.mts.map +1 -0
- package/dist/storage/helpers.mjs +34 -0
- package/dist/storage/helpers.mjs.map +1 -0
- package/dist/storage/index.cjs +12 -0
- package/dist/storage/index.d.cts +5 -0
- package/dist/storage/index.d.mts +5 -0
- package/dist/storage/index.mjs +6 -0
- package/dist/storage/virtual.cjs +98 -0
- package/dist/storage/virtual.d.cts +80 -0
- package/dist/storage/virtual.d.cts.map +1 -0
- package/dist/storage/virtual.d.mts +80 -0
- package/dist/storage/virtual.d.mts.map +1 -0
- package/dist/storage/virtual.mjs +97 -0
- package/dist/storage/virtual.mjs.map +1 -0
- package/dist/types/api.d.cts +18 -152
- package/dist/types/api.d.cts.map +1 -1
- package/dist/types/api.d.mts +18 -152
- package/dist/types/api.d.mts.map +1 -1
- package/dist/types/config.d.cts +194 -135
- package/dist/types/config.d.cts.map +1 -1
- package/dist/types/config.d.mts +195 -136
- package/dist/types/config.d.mts.map +1 -1
- package/dist/types/context.d.cts +152 -128
- package/dist/types/context.d.cts.map +1 -1
- package/dist/types/context.d.mts +155 -131
- package/dist/types/context.d.mts.map +1 -1
- package/dist/types/fs.d.mts +1 -1
- package/dist/types/index.d.cts +5 -6
- package/dist/types/index.d.mts +5 -6
- package/dist/types/logging.d.cts +161 -0
- package/dist/types/logging.d.cts.map +1 -0
- package/dist/types/logging.d.mts +161 -0
- package/dist/types/logging.d.mts.map +1 -0
- package/dist/types/plugin.d.cts +6 -9
- package/dist/types/plugin.d.cts.map +1 -1
- package/dist/types/plugin.d.mts +6 -9
- package/dist/types/plugin.d.mts.map +1 -1
- package/dist/types/tsconfig.d.mts +1 -1
- package/dist/types/unplugin.d.cts +5 -26
- package/dist/types/unplugin.d.cts.map +1 -1
- package/dist/types/unplugin.d.mts +5 -26
- package/dist/types/unplugin.d.mts.map +1 -1
- package/package.json +259 -457
- package/schemas/fs.capnp +42 -0
- package/dist/constants/virtual-modules.cjs +0 -8
- package/dist/constants/virtual-modules.d.cts +0 -6
- package/dist/constants/virtual-modules.d.cts.map +0 -1
- package/dist/constants/virtual-modules.d.mts +0 -6
- package/dist/constants/virtual-modules.d.mts.map +0 -1
- package/dist/constants/virtual-modules.mjs +0 -7
- package/dist/constants/virtual-modules.mjs.map +0 -1
- package/dist/lib/logger.cjs +0 -99
- package/dist/lib/logger.d.cts +0 -53
- package/dist/lib/logger.d.cts.map +0 -1
- package/dist/lib/logger.d.mts +0 -53
- package/dist/lib/logger.d.mts.map +0 -1
- package/dist/lib/logger.mjs +0 -93
- package/dist/lib/logger.mjs.map +0 -1
- package/dist/types/_internal.cjs +0 -0
- package/dist/types/_internal.d.cts +0 -106
- package/dist/types/_internal.d.cts.map +0 -1
- package/dist/types/_internal.d.mts +0 -106
- package/dist/types/_internal.d.mts.map +0 -1
- package/dist/types/_internal.mjs +0 -1
- package/dist/types/commands.d.cts +0 -16
- package/dist/types/commands.d.cts.map +0 -1
- package/dist/types/commands.d.mts +0 -16
- package/dist/types/commands.d.mts.map +0 -1
- package/dist/types/utils.d.cts +0 -9
- package/dist/types/utils.d.cts.map +0 -1
- package/dist/types/utils.d.mts +0 -9
- package/dist/types/utils.d.mts.map +0 -1
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
import { format } from "./utilities/format.mjs";
|
|
2
|
+
import { callHook } from "./hooks.mjs";
|
|
3
|
+
import { createProgram } from "./typescript/ts-morph.mjs";
|
|
4
|
+
import { getTypescriptFileHeader } from "./utilities/file-header.mjs";
|
|
5
|
+
import { appendPath } from "@stryke/path/append";
|
|
6
|
+
import { findFileName } from "@stryke/path/file-path-fns";
|
|
7
|
+
import { replaceExtension, replacePath } from "@stryke/path/replace";
|
|
8
|
+
import { isSetObject } from "@stryke/type-checks/is-set-object";
|
|
9
|
+
import { isSetString } from "@stryke/type-checks/is-set-string";
|
|
10
|
+
import { isString } from "@stryke/type-checks/is-string";
|
|
11
|
+
import { toArray } from "@stryke/convert/to-array";
|
|
12
|
+
import { isObject } from "@stryke/type-checks/is-object";
|
|
13
|
+
import { getUnique } from "@stryke/helpers/get-unique";
|
|
14
|
+
import { isParentPath } from "@stryke/path/is-parent-path";
|
|
15
|
+
import { resolvePackage } from "@stryke/fs/resolve";
|
|
16
|
+
import { prettyBytes } from "@stryke/string-format/pretty-bytes";
|
|
17
|
+
import { DiagnosticCategory, Node, Project } from "ts-morph";
|
|
18
|
+
|
|
19
|
+
//#region src/lib/generate-types.ts
|
|
20
|
+
/**
|
|
21
|
+
* Formats the generated TypeScript types source code.
|
|
22
|
+
*
|
|
23
|
+
* @param code - The generated TypeScript code.
|
|
24
|
+
* @returns The formatted TypeScript code.
|
|
25
|
+
*/
|
|
26
|
+
function formatTypes(code = "") {
|
|
27
|
+
return code.replaceAll("#private;", "").replace(/__Ω/g, "");
|
|
28
|
+
}
|
|
29
|
+
async function extractModuleDeclarations(ctx, filePath, name, text) {
|
|
30
|
+
const imports = [];
|
|
31
|
+
const exports = [];
|
|
32
|
+
const comment = text.match(new RegExp(`\\/\\*\\*(?s:.)*?@module\\s+${ctx.context.config.framework?.name ?? "powerlines"}:${name}(?s:.)*?\\*\\/\\s+`))?.find((comment) => isSetString(comment?.trim()));
|
|
33
|
+
const sourceFile = new Project({ useInMemoryFileSystem: true }).createSourceFile("module.d.ts", text);
|
|
34
|
+
for (const ref of sourceFile.getTypeReferenceDirectives()) if (ref.getFileName() && !ctx.context.builtins.some((builtin) => ref.getFileName().endsWith(builtin))) imports.push({
|
|
35
|
+
name: ref.getFileName(),
|
|
36
|
+
ambient: true
|
|
37
|
+
});
|
|
38
|
+
for (const statement of sourceFile.getStatements()) if (Node.isImportDeclaration(statement)) {
|
|
39
|
+
const moduleSpec = statement.getModuleSpecifierValue();
|
|
40
|
+
if (statement.getNamespaceImport()) imports.push({
|
|
41
|
+
name: moduleSpec,
|
|
42
|
+
specifiers: [{ name: statement.getNamespaceImport().getText() }],
|
|
43
|
+
all: true
|
|
44
|
+
});
|
|
45
|
+
else if (statement.getNamedImports().length > 0 || statement.getDefaultImport()) {
|
|
46
|
+
const specifiers = [];
|
|
47
|
+
if (statement.getDefaultImport()) specifiers.push({
|
|
48
|
+
name: statement.getDefaultImport().getText(),
|
|
49
|
+
default: true,
|
|
50
|
+
type: statement.isTypeOnly()
|
|
51
|
+
});
|
|
52
|
+
statement.getNamedImports().forEach((named) => {
|
|
53
|
+
specifiers.push({
|
|
54
|
+
name: named.getName(),
|
|
55
|
+
alias: named.getAliasNode()?.getText(),
|
|
56
|
+
type: statement.isTypeOnly()
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
imports.push({
|
|
60
|
+
name: moduleSpec,
|
|
61
|
+
specifiers
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
} else if (Node.isExportDeclaration(statement)) {
|
|
65
|
+
const moduleSpec = statement.getModuleSpecifierValue();
|
|
66
|
+
if (moduleSpec) {
|
|
67
|
+
let resolvedSpec = moduleSpec;
|
|
68
|
+
if (!ctx.context.builtins.includes(moduleSpec)) if (ctx.emitted.has(moduleSpec)) resolvedSpec = ctx.emitted.get(moduleSpec);
|
|
69
|
+
else {
|
|
70
|
+
const resolvedModule = await ctx.context.resolve(moduleSpec, filePath);
|
|
71
|
+
if (isSetString(resolvedModule?.id)) resolvedSpec = resolvedModule.id;
|
|
72
|
+
}
|
|
73
|
+
const namedExports = statement.getNamedExports();
|
|
74
|
+
if (namedExports.length > 0) exports.push({
|
|
75
|
+
name: resolvedSpec,
|
|
76
|
+
text: statement.getText(),
|
|
77
|
+
fullText: statement.getFullText(),
|
|
78
|
+
specifiers: namedExports.map((named) => ({
|
|
79
|
+
name: named.getName(),
|
|
80
|
+
alias: named.getAliasNode()?.getText(),
|
|
81
|
+
type: statement.isTypeOnly()
|
|
82
|
+
})),
|
|
83
|
+
comment: statement.getLeadingCommentRanges().filter((c) => isSetString(c.getText().trim()) && !c.getText().includes("@module")).map((c) => c.getText().trim()).join("\n").trim()
|
|
84
|
+
});
|
|
85
|
+
else exports.push({
|
|
86
|
+
name: resolvedSpec,
|
|
87
|
+
text: statement.getText(),
|
|
88
|
+
fullText: statement.getFullText(),
|
|
89
|
+
all: true,
|
|
90
|
+
comment: statement.getLeadingCommentRanges().filter((c) => isSetString(c.getText().trim()) && !c.getText().includes("@module")).map((c) => c.getText().trim()).join("\n").trim()
|
|
91
|
+
});
|
|
92
|
+
} else {
|
|
93
|
+
const specifiers = statement.getNamedExports().map((named) => ({
|
|
94
|
+
name: named.getName(),
|
|
95
|
+
alias: named.getAliasNode()?.getText(),
|
|
96
|
+
type: statement.isTypeOnly()
|
|
97
|
+
}));
|
|
98
|
+
if (specifiers.length > 0) exports.push({
|
|
99
|
+
text: statement.getText(),
|
|
100
|
+
fullText: statement.getFullText(),
|
|
101
|
+
specifiers,
|
|
102
|
+
comment: statement.getLeadingCommentRanges().filter((c) => isSetString(c.getText().trim()) && !c.getText().includes("@module")).map((c) => c.getText().trim()).join("\n")
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
} else if (Node.isExportAssignment(statement)) exports.push({
|
|
106
|
+
text: statement.getText(),
|
|
107
|
+
fullText: statement.getFullText(),
|
|
108
|
+
comment: statement.getLeadingCommentRanges().filter((c) => isSetString(c.getText().trim()) && !c.getText().includes("@module")).map((c) => c.getText().trim()).join("\n")
|
|
109
|
+
});
|
|
110
|
+
else if (Node.isFunctionDeclaration(statement) && statement.isExported() && statement.getNameNode()) exports.push({
|
|
111
|
+
text: statement.getText(),
|
|
112
|
+
fullText: statement.getFullText(),
|
|
113
|
+
specifiers: [{ name: statement.getNameNode().getText() }],
|
|
114
|
+
comment: statement.getLeadingCommentRanges().filter((c) => isSetString(c.getText().trim()) && !c.getText().includes("@module")).map((c) => c.getText().trim()).join("\n")
|
|
115
|
+
});
|
|
116
|
+
else if (Node.isVariableStatement(statement) && statement.isExported()) exports.push({
|
|
117
|
+
text: statement.getText(),
|
|
118
|
+
fullText: statement.getFullText(),
|
|
119
|
+
specifiers: statement.getDeclarationList().getDeclarations().filter((decl) => decl.getNameNode() && Node.isIdentifier(decl.getNameNode())).map((decl) => ({ name: decl.getNameNode().getText() })),
|
|
120
|
+
comment: statement.getLeadingCommentRanges().filter((c) => isSetString(c.getText().trim()) && !c.getText().includes("@module")).map((c) => c.getText().trim()).join("\n")
|
|
121
|
+
});
|
|
122
|
+
else if (Node.isClassDeclaration(statement) && statement.isExported()) {
|
|
123
|
+
const nameNode = statement.getNameNode();
|
|
124
|
+
exports.push({
|
|
125
|
+
text: statement.getText(),
|
|
126
|
+
fullText: statement.getFullText(),
|
|
127
|
+
specifiers: nameNode ? [{ name: nameNode.getText() }] : void 0,
|
|
128
|
+
comment: statement.getLeadingCommentRanges().filter((c) => isSetString(c.getText().trim()) && !c.getText().includes("@module")).map((c) => c.getText().trim()).join("\n")
|
|
129
|
+
});
|
|
130
|
+
} else if (Node.isInterfaceDeclaration(statement) && statement.isExported()) {
|
|
131
|
+
const nameNode = statement.getNameNode();
|
|
132
|
+
exports.push({
|
|
133
|
+
text: statement.getText(),
|
|
134
|
+
fullText: statement.getFullText(),
|
|
135
|
+
specifiers: nameNode ? [{ name: nameNode.getText() }] : void 0,
|
|
136
|
+
comment: statement.getLeadingCommentRanges().filter((c) => isSetString(c.getText().trim()) && !c.getText().includes("@module")).map((c) => c.getText().trim()).join("\n")
|
|
137
|
+
});
|
|
138
|
+
} else if (Node.isTypeAliasDeclaration(statement) && statement.isExported()) {
|
|
139
|
+
const nameNode = statement.getNameNode();
|
|
140
|
+
exports.push({
|
|
141
|
+
text: statement.getText(),
|
|
142
|
+
fullText: statement.getFullText(),
|
|
143
|
+
specifiers: nameNode ? [{ name: nameNode.getText() }] : void 0,
|
|
144
|
+
comment: statement.getLeadingCommentRanges().filter((c) => isSetString(c.getText().trim()) && !c.getText().includes("@module")).map((c) => c.getText().trim()).join("\n")
|
|
145
|
+
});
|
|
146
|
+
} else if (ctx.context.config.output.sourceMap || !statement.getFullText().includes("//# sourceMappingURL=")) exports.push({
|
|
147
|
+
text: statement.getText(),
|
|
148
|
+
fullText: statement.getFullText(),
|
|
149
|
+
comment: statement.getLeadingCommentRanges().filter((c) => isSetString(c.getText().trim()) && !c.getText().includes("@module")).map((c) => c.getText().trim()).join("\n")
|
|
150
|
+
});
|
|
151
|
+
return {
|
|
152
|
+
name,
|
|
153
|
+
text,
|
|
154
|
+
sourceFile,
|
|
155
|
+
comment,
|
|
156
|
+
imports,
|
|
157
|
+
exports
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Emits TypeScript declaration types for the provided files using the given TypeScript configuration.
|
|
162
|
+
*
|
|
163
|
+
* @param context - The context containing options and environment paths.
|
|
164
|
+
* @param files - The list of files to generate types for.
|
|
165
|
+
* @returns A promise that resolves to the generated TypeScript declaration types.
|
|
166
|
+
*/
|
|
167
|
+
async function emitBuiltinTypes(context, files) {
|
|
168
|
+
if (files.length === 0) {
|
|
169
|
+
context.debug("No files provided for TypeScript types generation. Typescript compilation for built-in modules will be skipped.");
|
|
170
|
+
return {
|
|
171
|
+
code: "",
|
|
172
|
+
directives: []
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
context.debug(`Running the TypeScript compiler for ${files.length} generated built-in module files.`);
|
|
176
|
+
const program = createProgram(context, {
|
|
177
|
+
skipAddingFilesFromTsConfig: true,
|
|
178
|
+
compilerOptions: {
|
|
179
|
+
declaration: true,
|
|
180
|
+
declarationMap: false,
|
|
181
|
+
emitDeclarationOnly: true,
|
|
182
|
+
sourceMap: false,
|
|
183
|
+
outDir: replacePath(context.builtinsPath, context.config.cwd),
|
|
184
|
+
composite: false,
|
|
185
|
+
incremental: false,
|
|
186
|
+
tsBuildInfoFile: void 0
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
program.addSourceFilesAtPaths(files);
|
|
190
|
+
const emitResult = program.emitToMemory({ emitOnlyDtsFiles: true });
|
|
191
|
+
const diagnostics = emitResult.getDiagnostics();
|
|
192
|
+
if (diagnostics && diagnostics.length > 0) if (diagnostics.some((d) => d.getCategory() === DiagnosticCategory.Error)) throw new Error(`The Typescript emit process failed while generating built-in types: \n ${diagnostics.filter((d) => d.getCategory() === DiagnosticCategory.Error).map((d) => `-${d.getSourceFile() ? `${d.getSourceFile()?.getFilePath()}:` : ""} ${String(d.getMessageText())} (at ${d.getStart()}:${d.getLength()})`).join("\n")}`);
|
|
193
|
+
else if (diagnostics.some((d) => d.getCategory() === DiagnosticCategory.Warning)) context.warn(`The Typescript emit process completed with warnings while generating built-in types: \n ${diagnostics.filter((d) => d.getCategory() === DiagnosticCategory.Warning).map((d) => `-${d.getSourceFile() ? `${d.getSourceFile()?.getFilePath()}:` : ""} ${String(d.getMessageText())} (at ${d.getStart()}:${d.getLength()})`).join("\n")}`);
|
|
194
|
+
else context.debug(`The Typescript emit process completed with diagnostic messages while generating built-in types: \n ${diagnostics.map((d) => `-${d.getSourceFile() ? `${d.getSourceFile()?.getFilePath()}:` : ""} ${String(d.getMessageText())} (at ${d.getStart()}:${d.getLength()})`).join("\n")}`);
|
|
195
|
+
const emittedFiles = emitResult.getFiles();
|
|
196
|
+
context.debug(`The TypeScript compiler emitted ${emittedFiles.length} files for built-in types.`);
|
|
197
|
+
if (emittedFiles.length === 0) {
|
|
198
|
+
context.warn("The TypeScript compiler did not emit any files for built-in types. This may indicate an issue with the TypeScript configuration or the provided files.");
|
|
199
|
+
return {
|
|
200
|
+
code: "",
|
|
201
|
+
directives: []
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
const ctx = {
|
|
205
|
+
context,
|
|
206
|
+
modules: [],
|
|
207
|
+
emitted: /* @__PURE__ */ new Map()
|
|
208
|
+
};
|
|
209
|
+
await Promise.all(emittedFiles.map(async (emittedFile) => {
|
|
210
|
+
const filePath = appendPath(emittedFile.filePath, context.config.cwd);
|
|
211
|
+
if (!filePath.endsWith(".map") && findFileName(filePath) !== "tsconfig.tsbuildinfo" && isParentPath(filePath, context.builtinsPath)) {
|
|
212
|
+
const moduleName = replaceExtension(replacePath(replacePath(filePath, context.builtinsPath), replacePath(context.builtinsPath, context.config.cwd)), "", { fullExtension: true });
|
|
213
|
+
if (context.builtins.includes(moduleName)) {
|
|
214
|
+
ctx.emitted.set(filePath, moduleName);
|
|
215
|
+
ctx.modules.push(await extractModuleDeclarations(ctx, filePath, moduleName, emittedFile.text));
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}));
|
|
219
|
+
const commonDeclarations = [];
|
|
220
|
+
for (const mod of ctx.modules) for (const importRef of mod.imports.filter((importRef) => context.builtins.some((builtin) => importRef.name.endsWith(`:${builtin}`)))) {
|
|
221
|
+
const moduleRef = ctx.modules.find((moduleRef) => importRef.name.endsWith(`:${moduleRef.name}`));
|
|
222
|
+
if (moduleRef) {
|
|
223
|
+
let declaration;
|
|
224
|
+
for (const decl of moduleRef.exports.filter((decl) => isSetObject(decl))) {
|
|
225
|
+
const specifiers = decl.specifiers?.filter((specifier) => importRef.specifiers?.some((s) => (specifier.alias ? specifier.alias : specifier.name) === (s.alias ? s.alias : s.name)));
|
|
226
|
+
if (specifiers && specifiers.length > 0) {
|
|
227
|
+
importRef.specifiers = importRef.specifiers?.filter((s) => !specifiers.some((specifier) => (specifier.alias ? specifier.alias : specifier.name) === (s.alias ? s.alias : s.name)));
|
|
228
|
+
if (importRef.specifiers && importRef.specifiers.length === 0 && !importRef.all && !importRef.ambient) mod.imports = mod.imports.filter((imp) => imp.name !== importRef.name);
|
|
229
|
+
declaration = decl;
|
|
230
|
+
break;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
if (declaration) {
|
|
234
|
+
for (const decl of moduleRef.exports.filter((decl) => isSetObject(decl) && !decl.specifiers?.some((s) => declaration?.specifiers?.some((specifier) => (specifier.alias ? specifier.alias : specifier.name) === (s.alias ? s.alias : s.name))))) {
|
|
235
|
+
const exportModuleRef = decl;
|
|
236
|
+
if ((exportModuleRef.specifiers?.some((s) => s.alias || s.name) || exportModuleRef.name) && new RegExp(`(^|\\s|\\n|\\r\\n|\\(|\\)|<|>|{|}|\\[|\\]|\\!|\\?|\\.|,|\\*|&|:)(${exportModuleRef.specifiers?.map((s) => `${s.alias ? `${s.alias}|` : ""}${s.name}`).join("|") || exportModuleRef.name})($|\\s|\\n|\\r\\n|\\(|\\)|<|>|{|}|\\[|\\]|\\!|\\?|\\.|,|\\*|&|:|;)`).test(declaration.text)) commonDeclarations.push(exportModuleRef);
|
|
237
|
+
}
|
|
238
|
+
commonDeclarations.push(declaration);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
let code = "";
|
|
243
|
+
const directives = [];
|
|
244
|
+
for (const commonDeclaration of commonDeclarations) {
|
|
245
|
+
code += formatTypes(`${commonDeclaration.comment?.trim() ? commonDeclaration.comment.trim() : ""}${commonDeclaration.comment?.trim() ? "\n" : ""}${formatTypes(commonDeclaration.text.replace(/\s*export\s*/, "").replace(/\s*declare\s*interface\s*/, "interface ").replace(/\s*declare\s*type\s*/, "type "))}`);
|
|
246
|
+
code += "\n\n";
|
|
247
|
+
}
|
|
248
|
+
for (const mod of ctx.modules) {
|
|
249
|
+
code += mod.comment ? `${mod.comment.trim()}\n` : "";
|
|
250
|
+
code += `declare module "${context.config.framework?.name ?? "powerlines"}:${mod.name}" { \n`;
|
|
251
|
+
for (const importRef of mod.imports) if (importRef.ambient) code += directives.push(importRef.name);
|
|
252
|
+
else if (importRef.all) code += `\timport * as ${findFileName(importRef.name)} from "${importRef.name}";\n`;
|
|
253
|
+
else if (importRef.specifiers) {
|
|
254
|
+
const typeOnly = importRef.specifiers.every((s) => s.type) ? " type" : "";
|
|
255
|
+
const specifiers = importRef.specifiers.map((s) => s.alias ? `${s.name} as ${s.alias}` : s.name).join(", ");
|
|
256
|
+
code += `\timport${typeOnly} { ${specifiers} } from "${importRef.name}";\n`;
|
|
257
|
+
}
|
|
258
|
+
if (mod.imports.length > 0) code += "\n";
|
|
259
|
+
for (const exportRef of mod.exports.filter((e) => isString(e) || !e.specifiers || !commonDeclarations.some((commonDecl) => commonDecl.specifiers && commonDecl.specifiers.some((specifier) => e.specifiers?.some((s) => (s.alias ? s.alias : s.name) === (specifier.alias ? specifier.alias : specifier.name)))))) if (isSetString(exportRef)) code += `${exportRef}\n`;
|
|
260
|
+
else if (exportRef.name) {
|
|
261
|
+
if (exportRef.all) code += `${exportRef.comment?.trim() ? exportRef.comment.trim() : ""}${exportRef.comment?.trim() ? "\n" : ""}export * from "${exportRef.name}";\n`;
|
|
262
|
+
else if (exportRef.specifiers) {
|
|
263
|
+
if (exportRef.comment?.trim()) code += `${exportRef.comment.trim()}\n`;
|
|
264
|
+
code += `\texport${exportRef.specifiers.every((s) => s.type) ? " type" : ""} { ${exportRef.specifiers.map((s) => s.alias ? `${s.name} as ${s.alias}` : s.name).join(", ")} } from "${exportRef.name}";\n`;
|
|
265
|
+
}
|
|
266
|
+
} else code += `${exportRef.comment?.trim() ? exportRef.comment.trim() : ""}${exportRef.comment?.trim() ? "\n" : ""}${formatTypes(exportRef.text.replace(/\s*export\s*declare\s*/, "export ").replace(/\s*declare\s*/, " "))}\n`;
|
|
267
|
+
mod.exports.filter((e) => !isString(e) && e.specifiers && commonDeclarations.some((commonDeclaration) => commonDeclaration.specifiers && commonDeclaration.specifiers.some((specifier) => e.specifiers?.some((s) => (s.alias ? s.alias : s.name) === (specifier.alias ? specifier.alias : specifier.name))))).forEach((e, i, arr) => {
|
|
268
|
+
if (i === 0) code += "\nexport { ";
|
|
269
|
+
else code += ", ";
|
|
270
|
+
code += `${e?.specifiers?.filter((s) => commonDeclarations.some((commonDeclaration) => commonDeclaration.specifiers && commonDeclaration.specifiers.some((specifier) => (s.alias ? s.alias : s.name) === (specifier.alias ? specifier.alias : specifier.name)))).map((s) => s.alias ? `${s.name} as ${s.alias}` : s.name).join(", ") || ""}`;
|
|
271
|
+
if (i === arr.length - 1) code += ` };\n`;
|
|
272
|
+
});
|
|
273
|
+
code += "}";
|
|
274
|
+
code += "\n\n";
|
|
275
|
+
}
|
|
276
|
+
code = await format(context, context.typesPath, code);
|
|
277
|
+
context.debug(`A TypeScript declaration file (size: ${prettyBytes(new Blob(toArray(code)).size)}) emitted for the built-in modules types.`);
|
|
278
|
+
return {
|
|
279
|
+
code,
|
|
280
|
+
directives
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Generate the Powerlines TypeScript declaration file
|
|
285
|
+
*
|
|
286
|
+
* @param context - The execution context for generating the TypeScript declaration file, which provides access to the project configuration, environment, and utility functions for performing the generation. The context is used to manage the state and behavior of the generation process, allowing for hooks to be called at different stages and for environment-specific configurations to be applied.
|
|
287
|
+
* @param env - The environment context to use for generating the TypeScript declaration file
|
|
288
|
+
*/
|
|
289
|
+
async function handleTypes(context, env) {
|
|
290
|
+
env.debug(`Preparing the TypeScript definitions for the Powerlines project.`);
|
|
291
|
+
if (env.fs.existsSync(env.typesPath)) await env.fs.remove(env.typesPath);
|
|
292
|
+
if (!await resolvePackage("typescript")) throw new Error("Could not resolve TypeScript package location. Please ensure TypeScript is installed.");
|
|
293
|
+
env.debug("Running TypeScript compiler for built-in runtime module files.");
|
|
294
|
+
let { code, directives } = await emitBuiltinTypes(env, (await env.getBuiltins()).reduce((ret, builtin) => {
|
|
295
|
+
const formatted = replacePath(builtin.path, env.config.cwd);
|
|
296
|
+
if (!ret.includes(formatted)) ret.push(formatted);
|
|
297
|
+
return ret;
|
|
298
|
+
}, []));
|
|
299
|
+
env.debug(`Generating TypeScript declaration file ${env.typesPath}.`);
|
|
300
|
+
const merge = async (currentResult, previousResult) => {
|
|
301
|
+
if (!isSetString(currentResult) && !isSetObject(currentResult) && !isSetString(previousResult) && !isSetObject(previousResult)) return {
|
|
302
|
+
code,
|
|
303
|
+
directives
|
|
304
|
+
};
|
|
305
|
+
const previous = (await format(env, env.typesPath, isSetString(previousResult) ? previousResult : isSetObject(previousResult) ? previousResult.code : "")).trim().replace(code, "").trim();
|
|
306
|
+
const current = (await format(env, env.typesPath, isSetString(currentResult) ? currentResult : isSetObject(currentResult) ? currentResult.code : "")).trim().replace(previous, "").trim().replace(code, "").trim();
|
|
307
|
+
return {
|
|
308
|
+
directives: [...isSetObject(currentResult) && currentResult.directives ? currentResult.directives : [], ...isSetObject(previousResult) && previousResult.directives ? previousResult.directives : []],
|
|
309
|
+
code: await format(env, env.typesPath, `${!previous.includes(getTypescriptFileHeader(env)) && !current.includes(getTypescriptFileHeader(env)) ? `${code}\n` : ""}${previous}\n${current}`.trim())
|
|
310
|
+
};
|
|
311
|
+
};
|
|
312
|
+
const asNextParam = (previousResult) => isObject(previousResult) ? previousResult.code : previousResult;
|
|
313
|
+
let result = await callHook(context, "types", {
|
|
314
|
+
environment: env,
|
|
315
|
+
sequential: true,
|
|
316
|
+
order: "pre",
|
|
317
|
+
result: "merge",
|
|
318
|
+
merge,
|
|
319
|
+
asNextParam
|
|
320
|
+
}, code);
|
|
321
|
+
if (result) {
|
|
322
|
+
if (isSetObject(result)) {
|
|
323
|
+
code = result.code;
|
|
324
|
+
if (Array.isArray(result.directives) && result.directives.length > 0) directives = getUnique([...directives, ...result.directives]).filter(Boolean);
|
|
325
|
+
} else if (isSetString(result)) code = result;
|
|
326
|
+
}
|
|
327
|
+
result = await callHook(context, "types", {
|
|
328
|
+
environment: env,
|
|
329
|
+
sequential: true,
|
|
330
|
+
order: "normal",
|
|
331
|
+
result: "merge",
|
|
332
|
+
merge,
|
|
333
|
+
asNextParam
|
|
334
|
+
}, code);
|
|
335
|
+
if (result) {
|
|
336
|
+
if (isSetObject(result)) {
|
|
337
|
+
code = result.code;
|
|
338
|
+
if (Array.isArray(result.directives) && result.directives.length > 0) directives = getUnique([...directives, ...result.directives]).filter(Boolean);
|
|
339
|
+
} else if (isSetString(result)) code = result;
|
|
340
|
+
}
|
|
341
|
+
result = await callHook(context, "types", {
|
|
342
|
+
environment: env,
|
|
343
|
+
sequential: true,
|
|
344
|
+
order: "post",
|
|
345
|
+
result: "merge",
|
|
346
|
+
merge,
|
|
347
|
+
asNextParam
|
|
348
|
+
}, code);
|
|
349
|
+
if (result) {
|
|
350
|
+
if (isSetObject(result)) {
|
|
351
|
+
code = result.code;
|
|
352
|
+
if (Array.isArray(result.directives) && result.directives.length > 0) directives = getUnique([...directives, ...result.directives]).filter(Boolean);
|
|
353
|
+
} else if (isSetString(result)) code = result;
|
|
354
|
+
}
|
|
355
|
+
if (isSetString(code?.trim()) || directives.length > 0) await env.fs.write(env.typesPath, `${directives.length > 0 ? `${directives.map((directive) => `/// <reference types="${directive}" />`).join("\n")}
|
|
356
|
+
|
|
357
|
+
` : ""}${getTypescriptFileHeader(env, {
|
|
358
|
+
directive: null,
|
|
359
|
+
prettierIgnore: false
|
|
360
|
+
})}
|
|
361
|
+
|
|
362
|
+
${formatTypes(code)}
|
|
363
|
+
`);
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
//#endregion
|
|
367
|
+
export { emitBuiltinTypes, formatTypes, handleTypes };
|
|
368
|
+
//# sourceMappingURL=generate-types.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-types.mjs","names":[],"sources":["../../src/lib/generate-types.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { toArray } from \"@stryke/convert/to-array\";\nimport { resolvePackage } from \"@stryke/fs/resolve\";\nimport { getUnique } from \"@stryke/helpers/get-unique\";\nimport { appendPath } from \"@stryke/path/append\";\nimport { findFileName } from \"@stryke/path/file-path-fns\";\nimport { isParentPath } from \"@stryke/path/is-parent-path\";\nimport { replaceExtension, replacePath } from \"@stryke/path/replace\";\nimport { prettyBytes } from \"@stryke/string-format/pretty-bytes\";\nimport { isObject } from \"@stryke/type-checks/is-object\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { isString } from \"@stryke/type-checks/is-string\";\nimport { DiagnosticCategory, Node, Project, SourceFile } from \"ts-morph\";\nimport { ResolvedConfig } from \"../types/config\";\nimport {\n Context,\n EnvironmentContext,\n ExecutionContext\n} from \"../types/context\";\nimport { TypesResult } from \"../types/plugin\";\nimport { callHook } from \"./hooks\";\nimport { createProgram } from \"./typescript/ts-morph\";\nimport { getTypescriptFileHeader } from \"./utilities/file-header\";\nimport { format } from \"./utilities/format\";\n\ninterface ModuleExportSpecifier {\n name: string;\n alias?: string;\n default?: boolean;\n type?: boolean;\n}\n\ninterface ModuleReference {\n name?: string;\n specifiers?: ModuleExportSpecifier[];\n all?: boolean;\n}\n\ninterface ImportModuleReference extends ModuleReference {\n name: string;\n ambient?: boolean;\n}\n\ninterface ExportModuleReference extends ModuleReference {\n text: string;\n fullText: string;\n comment?: string;\n}\n\ninterface ModuleDeclaration {\n name: string;\n text: string;\n sourceFile: SourceFile;\n comment?: string;\n exports: (ExportModuleReference | string)[];\n imports: ImportModuleReference[];\n}\n\nexport interface TypegenContext {\n context: Context;\n emitted: Map<string, string>;\n modules: ModuleDeclaration[];\n}\n\n/**\n * Formats the generated TypeScript types source code.\n *\n * @param code - The generated TypeScript code.\n * @returns The formatted TypeScript code.\n */\nexport function formatTypes(code = \"\"): string {\n return code.replaceAll(\"#private;\", \"\").replace(/__Ω/g, \"\");\n}\n\nasync function extractModuleDeclarations(\n ctx: TypegenContext,\n filePath: string,\n name: string,\n text: string\n): Promise<ModuleDeclaration> {\n const imports: ImportModuleReference[] = [];\n const exports: (ExportModuleReference | string)[] = [];\n\n const comment = text\n .match(\n new RegExp(\n `\\\\/\\\\*\\\\*(?s:.)*?@module\\\\s+${\n ctx.context.config.framework?.name ?? \"powerlines\"\n }:${name}(?s:.)*?\\\\*\\\\/\\\\s+`\n )\n )\n ?.find(comment => isSetString(comment?.trim()));\n\n // Parse the emitted .d.ts content using an in-memory ts-morph project\n const project = new Project({ useInMemoryFileSystem: true });\n const sourceFile = project.createSourceFile(\"module.d.ts\", text);\n\n // Collect /// <reference types=\"...\" /> directives as ambient dependencies\n for (const ref of sourceFile.getTypeReferenceDirectives()) {\n if (\n ref.getFileName() &&\n !ctx.context.builtins.some(builtin => ref.getFileName().endsWith(builtin))\n ) {\n imports.push({\n name: ref.getFileName(),\n ambient: true\n });\n }\n }\n\n for (const statement of sourceFile.getStatements()) {\n // --- Import declarations ---\n if (Node.isImportDeclaration(statement)) {\n const moduleSpec = statement.getModuleSpecifierValue();\n\n // Namespace import: import * as X from '...'\n if (statement.getNamespaceImport()) {\n imports.push({\n name: moduleSpec,\n specifiers: [\n {\n name: statement.getNamespaceImport()!.getText()\n }\n ],\n all: true\n });\n }\n\n // Named imports: import X from '...' or import { A, B as C } from '...'\n else if (\n statement.getNamedImports().length > 0 ||\n statement.getDefaultImport()\n ) {\n const specifiers: ModuleExportSpecifier[] = [];\n if (statement.getDefaultImport()) {\n specifiers.push({\n name: statement.getDefaultImport()!.getText(),\n default: true,\n type: statement.isTypeOnly()\n });\n }\n\n statement.getNamedImports().forEach(named => {\n specifiers.push({\n name: named.getName(),\n alias: named.getAliasNode()?.getText(),\n type: statement.isTypeOnly()\n });\n });\n\n imports.push({\n name: moduleSpec,\n specifiers\n });\n }\n }\n\n // --- Export declarations ---\n else if (Node.isExportDeclaration(statement)) {\n const moduleSpec = statement.getModuleSpecifierValue();\n if (moduleSpec) {\n // Resolve the module specifier\n let resolvedSpec = moduleSpec;\n if (!ctx.context.builtins.includes(moduleSpec)) {\n if (ctx.emitted.has(moduleSpec)) {\n resolvedSpec = ctx.emitted.get(moduleSpec)!;\n } else {\n const resolvedModule = await ctx.context.resolve(\n moduleSpec,\n filePath\n );\n if (isSetString(resolvedModule?.id)) {\n resolvedSpec = resolvedModule.id;\n }\n }\n }\n\n // Re-export from another module\n const namedExports = statement.getNamedExports();\n if (namedExports.length > 0) {\n exports.push({\n name: resolvedSpec,\n text: statement.getText(),\n fullText: statement.getFullText(),\n specifiers: namedExports.map(named => ({\n name: named.getName(),\n alias: named.getAliasNode()?.getText(),\n type: statement.isTypeOnly()\n })),\n comment: statement\n .getLeadingCommentRanges()\n .filter(\n c =>\n isSetString(c.getText().trim()) &&\n !c.getText().includes(\"@module\")\n )\n .map(c => c.getText().trim())\n .join(\"\\n\")\n .trim()\n });\n } else {\n // export * from '...'\n exports.push({\n name: resolvedSpec,\n text: statement.getText(),\n fullText: statement.getFullText(),\n all: true,\n comment: statement\n .getLeadingCommentRanges()\n .filter(\n c =>\n isSetString(c.getText().trim()) &&\n !c.getText().includes(\"@module\")\n )\n .map(c => c.getText().trim())\n .join(\"\\n\")\n .trim()\n });\n }\n } else {\n const specifiers = statement.getNamedExports().map(named => ({\n name: named.getName(),\n alias: named.getAliasNode()?.getText(),\n type: statement.isTypeOnly()\n }));\n if (specifiers.length > 0) {\n exports.push({\n text: statement.getText(),\n fullText: statement.getFullText(),\n specifiers,\n comment: statement\n .getLeadingCommentRanges()\n .filter(\n c =>\n isSetString(c.getText().trim()) &&\n !c.getText().includes(\"@module\")\n )\n .map(c => c.getText().trim())\n .join(\"\\n\")\n });\n }\n }\n }\n\n // --- Export assignments (export default ...) ---\n else if (Node.isExportAssignment(statement)) {\n exports.push({\n text: statement.getText(),\n fullText: statement.getFullText(),\n comment: statement\n .getLeadingCommentRanges()\n .filter(\n c =>\n isSetString(c.getText().trim()) &&\n !c.getText().includes(\"@module\")\n )\n .map(c => c.getText().trim())\n .join(\"\\n\")\n });\n }\n\n // --- Function declarations (export declare function ...) ---\n else if (\n Node.isFunctionDeclaration(statement) &&\n statement.isExported() &&\n statement.getNameNode()\n ) {\n exports.push({\n text: statement.getText(),\n fullText: statement.getFullText(),\n specifiers: [\n {\n name: statement.getNameNode()!.getText()\n }\n ],\n comment: statement\n .getLeadingCommentRanges()\n .filter(\n c =>\n isSetString(c.getText().trim()) &&\n !c.getText().includes(\"@module\")\n )\n .map(c => c.getText().trim())\n .join(\"\\n\")\n });\n }\n\n // --- Variable statements (export declare const ...) ---\n else if (Node.isVariableStatement(statement) && statement.isExported()) {\n exports.push({\n text: statement.getText(),\n fullText: statement.getFullText(),\n specifiers: statement\n .getDeclarationList()\n .getDeclarations()\n .filter(\n decl => decl.getNameNode() && Node.isIdentifier(decl.getNameNode())\n )\n .map(decl => ({ name: decl.getNameNode().getText() })),\n comment: statement\n .getLeadingCommentRanges()\n .filter(\n c =>\n isSetString(c.getText().trim()) &&\n !c.getText().includes(\"@module\")\n )\n .map(c => c.getText().trim())\n .join(\"\\n\")\n });\n }\n\n // --- Class declarations (export declare class ...) ---\n else if (Node.isClassDeclaration(statement) && statement.isExported()) {\n const nameNode = statement.getNameNode();\n exports.push({\n text: statement.getText(),\n fullText: statement.getFullText(),\n specifiers: nameNode ? [{ name: nameNode.getText() }] : undefined,\n comment: statement\n .getLeadingCommentRanges()\n .filter(\n c =>\n isSetString(c.getText().trim()) &&\n !c.getText().includes(\"@module\")\n )\n .map(c => c.getText().trim())\n .join(\"\\n\")\n });\n }\n\n // --- Interface declarations (export declare interface ...) ---\n else if (Node.isInterfaceDeclaration(statement) && statement.isExported()) {\n const nameNode = statement.getNameNode();\n exports.push({\n text: statement.getText(),\n fullText: statement.getFullText(),\n specifiers: nameNode ? [{ name: nameNode.getText() }] : undefined,\n comment: statement\n .getLeadingCommentRanges()\n .filter(\n c =>\n isSetString(c.getText().trim()) &&\n !c.getText().includes(\"@module\")\n )\n .map(c => c.getText().trim())\n .join(\"\\n\")\n });\n }\n\n // --- Type alias declarations (export declare type ...) ---\n else if (Node.isTypeAliasDeclaration(statement) && statement.isExported()) {\n const nameNode = statement.getNameNode();\n exports.push({\n text: statement.getText(),\n fullText: statement.getFullText(),\n specifiers: nameNode ? [{ name: nameNode.getText() }] : undefined,\n comment: statement\n .getLeadingCommentRanges()\n .filter(\n c =>\n isSetString(c.getText().trim()) &&\n !c.getText().includes(\"@module\")\n )\n .map(c => c.getText().trim())\n .join(\"\\n\")\n });\n }\n\n // --- All other statements (declarations) ---\n else if (\n ctx.context.config.output.sourceMap ||\n !statement.getFullText().includes(\"//# sourceMappingURL=\")\n ) {\n exports.push({\n text: statement.getText(),\n fullText: statement.getFullText(),\n comment: statement\n .getLeadingCommentRanges()\n .filter(\n c =>\n isSetString(c.getText().trim()) &&\n !c.getText().includes(\"@module\")\n )\n .map(c => c.getText().trim())\n .join(\"\\n\")\n });\n }\n }\n\n return {\n name,\n text,\n sourceFile,\n comment,\n imports,\n exports\n };\n}\n\n/**\n * Emits TypeScript declaration types for the provided files using the given TypeScript configuration.\n *\n * @param context - The context containing options and environment paths.\n * @param files - The list of files to generate types for.\n * @returns A promise that resolves to the generated TypeScript declaration types.\n */\nexport async function emitBuiltinTypes<TContext extends Context>(\n context: TContext,\n files: string[]\n): Promise<{ code: string; directives: string[] }> {\n if (files.length === 0) {\n context.debug(\n \"No files provided for TypeScript types generation. Typescript compilation for built-in modules will be skipped.\"\n );\n return { code: \"\", directives: [] };\n }\n\n context.debug(\n `Running the TypeScript compiler for ${\n files.length\n } generated built-in module files.`\n );\n\n const program = createProgram(context, {\n skipAddingFilesFromTsConfig: true,\n compilerOptions: {\n declaration: true,\n declarationMap: false,\n emitDeclarationOnly: true,\n sourceMap: false,\n outDir: replacePath(context.builtinsPath, context.config.cwd),\n composite: false,\n incremental: false,\n tsBuildInfoFile: undefined\n }\n });\n\n program.addSourceFilesAtPaths(files);\n const emitResult = program.emitToMemory({ emitOnlyDtsFiles: true });\n\n const diagnostics = emitResult.getDiagnostics();\n if (diagnostics && diagnostics.length > 0) {\n if (diagnostics.some(d => d.getCategory() === DiagnosticCategory.Error)) {\n throw new Error(\n `The Typescript emit process failed while generating built-in types: \\n ${diagnostics\n .filter(d => d.getCategory() === DiagnosticCategory.Error)\n .map(\n d =>\n `-${d.getSourceFile() ? `${d.getSourceFile()?.getFilePath()}:` : \"\"} ${String(\n d.getMessageText()\n )} (at ${d.getStart()}:${d.getLength()})`\n )\n .join(\"\\n\")}`\n );\n } else if (\n diagnostics.some(d => d.getCategory() === DiagnosticCategory.Warning)\n ) {\n context.warn(\n `The Typescript emit process completed with warnings while generating built-in types: \\n ${diagnostics\n .filter(d => d.getCategory() === DiagnosticCategory.Warning)\n .map(\n d =>\n `-${d.getSourceFile() ? `${d.getSourceFile()?.getFilePath()}:` : \"\"} ${String(\n d.getMessageText()\n )} (at ${d.getStart()}:${d.getLength()})`\n )\n .join(\"\\n\")}`\n );\n } else {\n context.debug(\n `The Typescript emit process completed with diagnostic messages while generating built-in types: \\n ${diagnostics\n .map(\n d =>\n `-${d.getSourceFile() ? `${d.getSourceFile()?.getFilePath()}:` : \"\"} ${String(\n d.getMessageText()\n )} (at ${d.getStart()}:${d.getLength()})`\n )\n .join(\"\\n\")}`\n );\n }\n }\n\n const emittedFiles = emitResult.getFiles();\n context.debug(\n `The TypeScript compiler emitted ${\n emittedFiles.length\n } files for built-in types.`\n );\n\n if (emittedFiles.length === 0) {\n context.warn(\n \"The TypeScript compiler did not emit any files for built-in types. This may indicate an issue with the TypeScript configuration or the provided files.\"\n );\n return { code: \"\", directives: [] };\n }\n\n const ctx = {\n context,\n modules: [] as ModuleDeclaration[],\n emitted: new Map<string, string>()\n };\n\n await Promise.all(\n emittedFiles.map(async emittedFile => {\n const filePath = appendPath(emittedFile.filePath, context.config.cwd);\n if (\n !filePath.endsWith(\".map\") &&\n findFileName(filePath) !== \"tsconfig.tsbuildinfo\" &&\n isParentPath(filePath, context.builtinsPath)\n ) {\n const moduleName = replaceExtension(\n replacePath(\n replacePath(filePath, context.builtinsPath),\n replacePath(context.builtinsPath, context.config.cwd)\n ),\n \"\",\n {\n fullExtension: true\n }\n );\n if (context.builtins.includes(moduleName)) {\n ctx.emitted.set(filePath, moduleName);\n ctx.modules.push(\n await extractModuleDeclarations(\n ctx,\n filePath,\n moduleName,\n emittedFile.text\n )\n );\n }\n }\n })\n );\n\n const commonDeclarations = [] as ExportModuleReference[];\n for (const mod of ctx.modules) {\n for (const importRef of mod.imports.filter(importRef =>\n context.builtins.some(builtin => importRef.name.endsWith(`:${builtin}`))\n )) {\n const moduleRef = ctx.modules.find(moduleRef =>\n importRef.name.endsWith(`:${moduleRef.name}`)\n );\n if (moduleRef) {\n let declaration: ExportModuleReference | undefined;\n for (const decl of moduleRef.exports.filter(decl =>\n isSetObject(decl)\n )) {\n const specifiers = decl.specifiers?.filter(specifier =>\n importRef.specifiers?.some(\n s =>\n (specifier.alias ? specifier.alias : specifier.name) ===\n (s.alias ? s.alias : s.name)\n )\n );\n if (specifiers && specifiers.length > 0) {\n importRef.specifiers = importRef.specifiers?.filter(\n s =>\n !specifiers.some(\n specifier =>\n (specifier.alias ? specifier.alias : specifier.name) ===\n (s.alias ? s.alias : s.name)\n )\n );\n if (\n importRef.specifiers &&\n importRef.specifiers.length === 0 &&\n !importRef.all &&\n !importRef.ambient\n ) {\n mod.imports = mod.imports.filter(\n imp => imp.name !== importRef.name\n );\n }\n\n declaration = decl;\n break;\n }\n }\n\n if (declaration) {\n for (const decl of moduleRef.exports.filter(\n decl =>\n isSetObject(decl) &&\n !decl.specifiers?.some(s =>\n declaration?.specifiers?.some(\n specifier =>\n (specifier.alias ? specifier.alias : specifier.name) ===\n (s.alias ? s.alias : s.name)\n )\n )\n )) {\n const exportModuleRef = decl as ExportModuleReference;\n if (\n (exportModuleRef.specifiers?.some(s => s.alias || s.name) ||\n exportModuleRef.name) &&\n new RegExp(\n `(^|\\\\s|\\\\n|\\\\r\\\\n|\\\\(|\\\\)|<|>|{|}|\\\\[|\\\\]|\\\\!|\\\\?|\\\\.|,|\\\\*|&|:)(${\n exportModuleRef.specifiers\n ?.map(s => `${s.alias ? `${s.alias}|` : \"\"}${s.name}`)\n .join(\"|\") || exportModuleRef.name\n })($|\\\\s|\\\\n|\\\\r\\\\n|\\\\(|\\\\)|<|>|{|}|\\\\[|\\\\]|\\\\!|\\\\?|\\\\.|,|\\\\*|&|:|;)`\n ).test(declaration.text)\n ) {\n commonDeclarations.push(exportModuleRef);\n }\n }\n commonDeclarations.push(declaration);\n }\n }\n }\n }\n\n let code = \"\";\n const directives: string[] = [];\n\n for (const commonDeclaration of commonDeclarations) {\n code += formatTypes(\n `${\n commonDeclaration.comment?.trim()\n ? commonDeclaration.comment.trim()\n : \"\"\n }${commonDeclaration.comment?.trim() ? \"\\n\" : \"\"}${formatTypes(\n commonDeclaration.text\n .replace(/\\s*export\\s*/, \"\")\n .replace(/\\s*declare\\s*interface\\s*/, \"interface \")\n .replace(/\\s*declare\\s*type\\s*/, \"type \")\n )}`\n );\n code += \"\\n\\n\";\n }\n\n for (const mod of ctx.modules) {\n code += mod.comment ? `${mod.comment.trim()}\\n` : \"\";\n code += `declare module \"${context.config.framework?.name ?? \"powerlines\"}:${mod.name}\" { \\n`;\n for (const importRef of mod.imports) {\n if (importRef.ambient) {\n code += directives.push(importRef.name);\n } else if (importRef.all) {\n code += `\\timport * as ${findFileName(importRef.name)} from \"${importRef.name}\";\\n`;\n } else if (importRef.specifiers) {\n const typeOnly = importRef.specifiers.every(s => s.type) ? \" type\" : \"\";\n const specifiers = importRef.specifiers\n .map(s => (s.alias ? `${s.name} as ${s.alias}` : s.name))\n .join(\", \");\n code += `\\timport${typeOnly} { ${specifiers} } from \"${importRef.name}\";\\n`;\n }\n }\n\n if (mod.imports.length > 0) {\n code += \"\\n\";\n }\n\n for (const exportRef of mod.exports.filter(\n e =>\n isString(e) ||\n !e.specifiers ||\n !commonDeclarations.some(\n commonDecl =>\n commonDecl.specifiers &&\n commonDecl.specifiers.some(specifier =>\n e.specifiers?.some(\n s =>\n (s.alias ? s.alias : s.name) ===\n (specifier.alias ? specifier.alias : specifier.name)\n )\n )\n )\n )) {\n if (isSetString(exportRef)) {\n code += `${exportRef}\\n`;\n } else if (exportRef.name) {\n if (exportRef.all) {\n code += `${\n exportRef.comment?.trim() ? exportRef.comment.trim() : \"\"\n }${\n exportRef.comment?.trim() ? \"\\n\" : \"\"\n }export * from \"${exportRef.name}\";\\n`;\n } else if (exportRef.specifiers) {\n if (exportRef.comment?.trim()) {\n code += `${exportRef.comment.trim()}\\n`;\n }\n\n code += `\\texport${\n exportRef.specifiers.every(s => s.type) ? \" type\" : \"\"\n } { ${exportRef.specifiers\n .map(s => (s.alias ? `${s.name} as ${s.alias}` : s.name))\n .join(\", \")} } from \"${exportRef.name}\";\\n`;\n }\n } else {\n code += `${exportRef.comment?.trim() ? exportRef.comment.trim() : \"\"}${\n exportRef.comment?.trim() ? \"\\n\" : \"\"\n }${formatTypes(\n exportRef.text\n .replace(/\\s*export\\s*declare\\s*/, \"export \")\n .replace(/\\s*declare\\s*/, \" \")\n )}\\n`;\n }\n }\n\n mod.exports\n .filter(\n e =>\n !isString(e) &&\n e.specifiers &&\n commonDeclarations.some(\n commonDeclaration =>\n commonDeclaration.specifiers &&\n commonDeclaration.specifiers.some(specifier =>\n e.specifiers?.some(\n s =>\n (s.alias ? s.alias : s.name) ===\n (specifier.alias ? specifier.alias : specifier.name)\n )\n )\n )\n )\n .forEach((e, i, arr) => {\n if (i === 0) {\n code += \"\\nexport { \";\n } else {\n code += \", \";\n }\n\n code += `${\n (e as ExportModuleReference)?.specifiers\n ?.filter(s =>\n commonDeclarations.some(\n commonDeclaration =>\n commonDeclaration.specifiers &&\n commonDeclaration.specifiers.some(\n specifier =>\n (s.alias ? s.alias : s.name) ===\n (specifier.alias ? specifier.alias : specifier.name)\n )\n )\n )\n .map(s => (s.alias ? `${s.name} as ${s.alias}` : s.name))\n .join(\", \") || \"\"\n }`;\n\n if (i === arr.length - 1) {\n code += ` };\\n`;\n }\n });\n\n code += \"}\";\n code += \"\\n\\n\";\n }\n\n code = await format(context, context.typesPath, code);\n\n context.debug(\n `A TypeScript declaration file (size: ${prettyBytes(\n new Blob(toArray(code)).size\n )}) emitted for the built-in modules types.`\n );\n\n return { code, directives };\n}\n\n/**\n * Generate the Powerlines TypeScript declaration file\n *\n * @param context - The execution context for generating the TypeScript declaration file, which provides access to the project configuration, environment, and utility functions for performing the generation. The context is used to manage the state and behavior of the generation process, allowing for hooks to be called at different stages and for environment-specific configurations to be applied.\n * @param env - The environment context to use for generating the TypeScript declaration file\n */\nexport async function handleTypes<\n TResolvedConfig extends ResolvedConfig,\n TSystemContext = unknown\n>(\n context: ExecutionContext<TResolvedConfig, TSystemContext>,\n env: EnvironmentContext<TResolvedConfig, TSystemContext>\n) {\n env.debug(`Preparing the TypeScript definitions for the Powerlines project.`);\n\n if (env.fs.existsSync(env.typesPath)) {\n await env.fs.remove(env.typesPath);\n }\n\n const typescriptPath = await resolvePackage(\"typescript\");\n if (!typescriptPath) {\n throw new Error(\n \"Could not resolve TypeScript package location. Please ensure TypeScript is installed.\"\n );\n }\n\n env.debug(\"Running TypeScript compiler for built-in runtime module files.\");\n\n let { code, directives } = await emitBuiltinTypes(\n env,\n (await env.getBuiltins()).reduce<string[]>((ret, builtin) => {\n const formatted = replacePath(builtin.path, env.config.cwd);\n if (!ret.includes(formatted)) {\n ret.push(formatted);\n }\n\n return ret;\n }, [])\n );\n\n env.debug(`Generating TypeScript declaration file ${env.typesPath}.`);\n\n const merge = async (\n currentResult: string | TypesResult,\n previousResult: string | TypesResult\n ): Promise<string | TypesResult> => {\n if (\n !isSetString(currentResult) &&\n !isSetObject(currentResult) &&\n !isSetString(previousResult) &&\n !isSetObject(previousResult)\n ) {\n return { code, directives };\n }\n\n const previous = (\n await format(\n env,\n env.typesPath,\n isSetString(previousResult)\n ? previousResult\n : isSetObject(previousResult)\n ? previousResult.code\n : \"\"\n )\n )\n .trim()\n .replace(code, \"\")\n .trim();\n const current = (\n await format(\n env,\n env.typesPath,\n isSetString(currentResult)\n ? currentResult\n : isSetObject(currentResult)\n ? currentResult.code\n : \"\"\n )\n )\n .trim()\n .replace(previous, \"\")\n .trim()\n .replace(code, \"\")\n .trim();\n\n return {\n directives: [\n ...(isSetObject(currentResult) && currentResult.directives\n ? currentResult.directives\n : []),\n ...(isSetObject(previousResult) && previousResult.directives\n ? previousResult.directives\n : [])\n ],\n code: await format(\n env,\n env.typesPath,\n `${\n !previous.includes(getTypescriptFileHeader(env)) &&\n !current.includes(getTypescriptFileHeader(env))\n ? `${code}\\n`\n : \"\"\n }${previous}\\n${current}`.trim()\n )\n };\n };\n const asNextParam = (\n previousResult: string | TypesResult | null | undefined\n ) => (isObject(previousResult) ? previousResult.code : previousResult);\n\n let result = await callHook(\n context,\n \"types\",\n {\n environment: env,\n sequential: true,\n order: \"pre\",\n result: \"merge\",\n merge,\n asNextParam\n },\n code\n );\n if (result) {\n if (isSetObject(result)) {\n code = result.code;\n if (Array.isArray(result.directives) && result.directives.length > 0) {\n directives = getUnique([...directives, ...result.directives]).filter(\n Boolean\n );\n }\n } else if (isSetString(result)) {\n code = result;\n }\n }\n\n result = await callHook(\n context,\n \"types\",\n {\n environment: env,\n sequential: true,\n order: \"normal\",\n result: \"merge\",\n merge,\n asNextParam\n },\n code\n );\n if (result) {\n if (isSetObject(result)) {\n code = result.code;\n if (Array.isArray(result.directives) && result.directives.length > 0) {\n directives = getUnique([...directives, ...result.directives]).filter(\n Boolean\n );\n }\n } else if (isSetString(result)) {\n code = result;\n }\n }\n\n result = await callHook(\n context,\n \"types\",\n {\n environment: env,\n sequential: true,\n order: \"post\",\n result: \"merge\",\n merge,\n asNextParam\n },\n code\n );\n if (result) {\n if (isSetObject(result)) {\n code = result.code;\n if (Array.isArray(result.directives) && result.directives.length > 0) {\n directives = getUnique([...directives, ...result.directives]).filter(\n Boolean\n );\n }\n } else if (isSetString(result)) {\n code = result;\n }\n }\n\n if (isSetString(code?.trim()) || directives.length > 0) {\n await env.fs.write(\n env.typesPath,\n `${\n directives.length > 0\n ? `${directives.map(directive => `/// <reference types=\"${directive}\" />`).join(\"\\n\")}\n\n`\n : \"\"\n }${getTypescriptFileHeader(env, { directive: null, prettierIgnore: false })}\n\n${formatTypes(code)}\n`\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAwFA,SAAgB,YAAY,OAAO,IAAY;AAC7C,QAAO,KAAK,WAAW,aAAa,GAAG,CAAC,QAAQ,QAAQ,GAAG;;AAG7D,eAAe,0BACb,KACA,UACA,MACA,MAC4B;CAC5B,MAAM,UAAmC,EAAE;CAC3C,MAAM,UAA8C,EAAE;CAEtD,MAAM,UAAU,KACb,MACC,IAAI,OACF,+BACE,IAAI,QAAQ,OAAO,WAAW,QAAQ,aACvC,GAAG,KAAK,oBACV,CACF,EACC,MAAK,YAAW,YAAY,SAAS,MAAM,CAAC,CAAC;CAIjD,MAAM,aAAa,IADC,QAA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,UAAS,MAAM,SACb,SACA,SACA;EACE,aAAa;EACb,YAAY;EACZ,OAAO;EACP,QAAQ;EACR;EACA;EACD,EACD,KACD;AACD,KAAI,QACF;MAAI,YAAY,OAAO,EAAE;AACvB,UAAO,OAAO;AACd,OAAI,MAAM,QAAQ,OAAO,WAAW,IAAI,OAAO,WAAW,SAAS,EACjE,cAAa,UAAU,CAAC,GAAG,YAAY,GAAG,OAAO,WAAW,CAAC,CAAC,OAC5D,QACD;aAEM,YAAY,OAAO,CAC5B,QAAO;;AAIX,UAAS,MAAM,SACb,SACA,SACA;EACE,aAAa;EACb,YAAY;EACZ,OAAO;EACP,QAAQ;EACR;EACA;EACD,EACD,KACD;AACD,KAAI,QACF;MAAI,YAAY,OAAO,EAAE;AACvB,UAAO,OAAO;AACd,OAAI,MAAM,QAAQ,OAAO,WAAW,IAAI,OAAO,WAAW,SAAS,EACjE,cAAa,UAAU,CAAC,GAAG,YAAY,GAAG,OAAO,WAAW,CAAC,CAAC,OAC5D,QACD;aAEM,YAAY,OAAO,CAC5B,QAAO;;AAIX,KAAI,YAAY,MAAM,MAAM,CAAC,IAAI,WAAW,SAAS,EACnD,OAAM,IAAI,GAAG,MACX,IAAI,WACJ,GACE,WAAW,SAAS,IAChB,GAAG,WAAW,KAAI,cAAa,yBAAyB,UAAU,MAAM,CAAC,KAAK,KAAK,CAAC;;IAGpF,KACH,wBAAwB,KAAK;EAAE,WAAW;EAAM,gBAAgB;EAAO,CAAC,CAAC;;EAEhF,YAAY,KAAK,CAAC;EAEf"}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
|
+
const require_plugin_utils_logging = require('../plugin-utils/logging.cjs');
|
|
4
|
+
const require_plugin_utils_helpers = require('../plugin-utils/helpers.cjs');
|
|
5
|
+
const require_plugin_utils_merge = require('../plugin-utils/merge.cjs');
|
|
6
|
+
require('../plugin-utils/index.cjs');
|
|
7
|
+
let _stryke_type_checks_is_function = require("@stryke/type-checks/is-function");
|
|
8
|
+
let _stryke_type_checks_is_set_object = require("@stryke/type-checks/is-set-object");
|
|
9
|
+
let defu = require("defu");
|
|
10
|
+
let _stryke_type_checks_is_set_string = require("@stryke/type-checks/is-set-string");
|
|
11
|
+
let _stryke_type_checks_is_string = require("@stryke/type-checks/is-string");
|
|
12
|
+
let chalk = require("chalk");
|
|
13
|
+
chalk = require_runtime.__toESM(chalk, 1);
|
|
14
|
+
let _stryke_helpers_get_field = require("@stryke/helpers/get-field");
|
|
15
|
+
let _stryke_type_checks_is_object = require("@stryke/type-checks/is-object");
|
|
16
|
+
let _stryke_type_checks_is_set = require("@stryke/type-checks/is-set");
|
|
17
|
+
|
|
18
|
+
//#region src/lib/hooks.ts
|
|
19
|
+
/**
|
|
20
|
+
* Merges the current hook result with the previous results based on their types.
|
|
21
|
+
*
|
|
22
|
+
* @param currentResult - The current hook result to merge with the previous results.
|
|
23
|
+
* @param previousResults - The previous hook results to merge with the current result.
|
|
24
|
+
* @returns The merged result.
|
|
25
|
+
*/
|
|
26
|
+
function mergeResults(currentResult, previousResults) {
|
|
27
|
+
if (!previousResults || previousResults.length === 0) return [currentResult];
|
|
28
|
+
if ((0, _stryke_type_checks_is_set_string.isSetString)(currentResult)) previousResults = [`${(0, _stryke_type_checks_is_set_string.isSetString)(previousResults[0]) ? previousResults[0] || "" : ""}\n${(0, _stryke_type_checks_is_set_string.isSetString)(previousResults[0]) ? currentResult.replace(previousResults[0], "") : currentResult}`.trim()];
|
|
29
|
+
else if ((0, _stryke_type_checks_is_object.isObject)(currentResult)) previousResults = previousResults.length > 0 ? [(0, defu.defu)(currentResult, previousResults[0])] : [currentResult];
|
|
30
|
+
return previousResults;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Merges multiple hook results together, with special handling for string values and object values.
|
|
34
|
+
*
|
|
35
|
+
* @param currentResult - The current hook result to merge with the previous results.
|
|
36
|
+
* @param previousResults - The previous hook results to merge with the current result.
|
|
37
|
+
* @returns The merged result.
|
|
38
|
+
*/
|
|
39
|
+
function mergeConfigs(currentResult, previousResults) {
|
|
40
|
+
if ((0, _stryke_type_checks_is_string.isString)(currentResult)) previousResults = `${(0, _stryke_type_checks_is_string.isString)(previousResults) ? previousResults || "" : ""}\n${currentResult || ""}`.trim();
|
|
41
|
+
else if ((0, _stryke_type_checks_is_object.isObject)(currentResult)) previousResults = require_plugin_utils_merge.mergeConfig(currentResult, previousResults ?? {});
|
|
42
|
+
return previousResults;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Calls a hook with the given context, options, and arguments.
|
|
46
|
+
*
|
|
47
|
+
* @param context - The context to use when calling the hook.
|
|
48
|
+
* @param key - The hook to call.
|
|
49
|
+
* @param options - Options for calling the hook.
|
|
50
|
+
* @param args - Arguments to pass to the hook.
|
|
51
|
+
* @returns The return value of the hook.
|
|
52
|
+
*/
|
|
53
|
+
async function _callHook(context, key, options, ...args) {
|
|
54
|
+
const hooks = context.selectHooks(key, options);
|
|
55
|
+
if (hooks.length > 0) {
|
|
56
|
+
context.extendLogger({ category: "hooks" }).debug(`🧩 Calling ${hooks.length} ${chalk.default.bold.cyanBright(`${key}${options?.order ? ` (${options.order})` : ""}`)} plugin hook${hooks.length > 1 ? "s" : ""}:\n${hooks.map((hook, index) => ` ${index + 1}. ${require_plugin_utils_logging.colorText(hook.plugin.name)}`).join("\n")}`);
|
|
57
|
+
const invokeHook = async (hook, hookArgs) => {
|
|
58
|
+
return Reflect.apply(hook.handler, hook.context, hookArgs);
|
|
59
|
+
};
|
|
60
|
+
let results = [];
|
|
61
|
+
if (options?.sequential === false) results = await Promise.all(hooks.map(async (hook) => {
|
|
62
|
+
if (!(0, _stryke_type_checks_is_function.isFunction)(hook.handler)) throw new Error(`Plugin hook handler for hook "${key}" is not a function.`);
|
|
63
|
+
return invokeHook(hook, [...args]);
|
|
64
|
+
}));
|
|
65
|
+
else for (const hook of hooks) {
|
|
66
|
+
if (!(0, _stryke_type_checks_is_function.isFunction)(hook.handler)) throw new Error(`Plugin hook handler for hook "${key}" is not a function.`);
|
|
67
|
+
if (options?.result === "first" || options?.asNextParam === false) {
|
|
68
|
+
results.push(await Promise.resolve(invokeHook(hook, [...args])));
|
|
69
|
+
if (options?.result === "first" && (0, _stryke_type_checks_is_set.isSet)(results[results.length - 1])) break;
|
|
70
|
+
} else {
|
|
71
|
+
const sequenceArgs = [...args];
|
|
72
|
+
if (results.length > 0 && sequenceArgs.length > 0) sequenceArgs[0] = (0, _stryke_type_checks_is_function.isFunction)(options.asNextParam) ? await Promise.resolve(options.asNextParam(results[0])) : results[0];
|
|
73
|
+
const result = await Promise.resolve(invokeHook(hook, [...sequenceArgs]));
|
|
74
|
+
if (result) if (options.result === "last") results = [result];
|
|
75
|
+
else if (options.result === "merge" && options.merge) results = [results.length > 0 && results[0] ? await Promise.resolve(options.merge(result, results[0])) : result];
|
|
76
|
+
else results = mergeResults(result, results);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
const definedResults = results.filter((result) => (0, _stryke_type_checks_is_set.isSet)(result));
|
|
80
|
+
if (definedResults.length > 0) {
|
|
81
|
+
let mergedResult = void 0;
|
|
82
|
+
for (const result of definedResults) mergedResult = (0, defu.defu)(result, mergedResult ?? {});
|
|
83
|
+
return mergedResult;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
function extractHooks(context, hooks, plugin, key, parentKey) {
|
|
88
|
+
const combinedKey = parentKey ? `${parentKey}:${key}` : key;
|
|
89
|
+
const pluginField = (0, _stryke_helpers_get_field.getField)(plugin, combinedKey.replace(/:/g, "."));
|
|
90
|
+
if (require_plugin_utils_helpers.isPluginHookField(combinedKey) && require_plugin_utils_helpers.isPluginHook(pluginField)) {
|
|
91
|
+
const pluginHook = pluginField;
|
|
92
|
+
if (!require_plugin_utils_helpers.isPluginHook(pluginHook)) return hooks;
|
|
93
|
+
hooks[combinedKey] ??= {
|
|
94
|
+
preEnforced: [],
|
|
95
|
+
preOrdered: [],
|
|
96
|
+
normal: [],
|
|
97
|
+
postEnforced: [],
|
|
98
|
+
postOrdered: []
|
|
99
|
+
};
|
|
100
|
+
if (plugin.enforce) {
|
|
101
|
+
const hookListOrder = `${plugin.enforce}Enforced`;
|
|
102
|
+
hooks[combinedKey][hookListOrder] ??= [];
|
|
103
|
+
hooks[combinedKey][hookListOrder] = require_plugin_utils_helpers.addPluginHook(context, plugin, pluginHook, hooks[combinedKey][hookListOrder]);
|
|
104
|
+
return hooks;
|
|
105
|
+
}
|
|
106
|
+
if ((0, _stryke_type_checks_is_function.isFunction)(pluginHook) || !pluginHook.order) {
|
|
107
|
+
hooks[combinedKey].normal ??= [];
|
|
108
|
+
hooks[combinedKey].normal = require_plugin_utils_helpers.addPluginHook(context, plugin, pluginHook, hooks[combinedKey].normal);
|
|
109
|
+
return hooks;
|
|
110
|
+
}
|
|
111
|
+
const hookListOrder = `${pluginHook.order}Ordered`;
|
|
112
|
+
hooks[combinedKey][hookListOrder] ??= [];
|
|
113
|
+
hooks[combinedKey][hookListOrder] = require_plugin_utils_helpers.addPluginHook(context, plugin, pluginHook, hooks[combinedKey][hookListOrder]);
|
|
114
|
+
return hooks;
|
|
115
|
+
} else if ((0, _stryke_type_checks_is_set_object.isSetObject)(pluginField)) return Object.keys(pluginField).map((pluginKey) => extractHooks(context, hooks, plugin, pluginKey, combinedKey)).reduce((ret, current) => {
|
|
116
|
+
Object.keys(current).forEach((key) => {
|
|
117
|
+
ret[key] ??= {
|
|
118
|
+
preEnforced: [],
|
|
119
|
+
preOrdered: [],
|
|
120
|
+
normal: [],
|
|
121
|
+
postEnforced: [],
|
|
122
|
+
postOrdered: []
|
|
123
|
+
};
|
|
124
|
+
[
|
|
125
|
+
"preEnforced",
|
|
126
|
+
"preOrdered",
|
|
127
|
+
"normal",
|
|
128
|
+
"postEnforced",
|
|
129
|
+
"postOrdered"
|
|
130
|
+
].forEach((order) => {
|
|
131
|
+
if (current[key]?.[order]) {
|
|
132
|
+
ret[key][order] ??= [];
|
|
133
|
+
ret[key][order] = ret[key][order].concat(current[key][order]);
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
return ret;
|
|
138
|
+
}, hooks);
|
|
139
|
+
return hooks;
|
|
140
|
+
}
|
|
141
|
+
async function callHook(context, key, options, ...args) {
|
|
142
|
+
return _callHook((0, _stryke_type_checks_is_set_object.isSetObject)(options?.environment) ? options.environment : await context.getEnvironment(options?.environment), key, {
|
|
143
|
+
sequential: true,
|
|
144
|
+
...options
|
|
145
|
+
}, ...args);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
//#endregion
|
|
149
|
+
exports.callHook = callHook;
|
|
150
|
+
exports.extractHooks = extractHooks;
|
|
151
|
+
exports.mergeConfigs = mergeConfigs;
|
|
152
|
+
exports.mergeResults = mergeResults;
|