@esportsplus/typescript 0.29.6 → 0.31.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/README.md +97 -3
- package/bin/tsc-alias +1 -1
- package/bin/tsc-lsp +3 -0
- package/build/cli/diagnostics.d.ts +8 -0
- package/build/cli/diagnostics.js +95 -0
- package/build/cli/tsc.d.ts +12 -2
- package/build/cli/tsc.js +343 -52
- package/build/compiler/ast.d.ts +7 -5
- package/build/compiler/ast.js +6 -6
- package/build/compiler/code.d.ts +5 -4
- package/build/compiler/code.js +12 -1
- package/build/compiler/coordinator.d.ts +16 -7
- package/build/compiler/coordinator.js +75 -41
- package/build/compiler/imports.d.ts +8 -3
- package/build/compiler/imports.js +34 -24
- package/build/compiler/index.d.ts +3 -0
- package/build/compiler/index.js +1 -0
- package/build/compiler/language-service.d.ts +36 -6
- package/build/compiler/language-service.js +252 -58
- package/build/compiler/plugins/index.d.ts +4 -2
- package/build/compiler/plugins/tsc.d.ts +1 -1
- package/build/compiler/plugins/vite.d.ts +6 -3
- package/build/compiler/plugins/vite.js +15 -8
- package/build/compiler/sourcemap.d.ts +52 -0
- package/build/compiler/sourcemap.js +265 -0
- package/build/compiler/types.d.ts +7 -6
- package/build/compiler/uid.d.ts +5 -2
- package/build/compiler/uid.js +33 -4
- package/build/index.d.ts +1 -1
- package/build/index.js +1 -1
- package/build/jsonc.d.ts +2 -0
- package/build/jsonc.js +85 -0
- package/build/lsp/bin.d.ts +1 -0
- package/build/lsp/bin.js +2 -0
- package/build/lsp/diagnostics.d.ts +10 -0
- package/build/lsp/diagnostics.js +69 -0
- package/build/lsp/index.d.ts +2 -0
- package/build/lsp/index.js +2 -0
- package/build/lsp/server.d.ts +4 -0
- package/build/lsp/server.js +130 -0
- package/build/lsp/workspace.d.ts +14 -0
- package/build/lsp/workspace.js +46 -0
- package/build/probe/adapter.d.ts +14 -0
- package/build/probe/adapter.js +42 -0
- package/build/probe/async/channel.d.ts +4 -0
- package/build/probe/async/channel.js +560 -0
- package/build/probe/async/value.d.ts +9 -0
- package/build/probe/async/value.js +16 -0
- package/build/probe/channels.d.ts +4 -0
- package/build/probe/channels.js +16 -0
- package/build/probe/exceptions/channel.d.ts +5 -0
- package/build/probe/exceptions/channel.js +657 -0
- package/build/probe/exceptions/jsdoc.d.ts +8 -0
- package/build/probe/exceptions/jsdoc.js +34 -0
- package/build/probe/exceptions/value.d.ts +39 -0
- package/build/probe/exceptions/value.js +158 -0
- package/build/probe/kernel/analyze.d.ts +8 -0
- package/build/probe/kernel/analyze.js +68 -0
- package/build/probe/kernel/ast.d.ts +11 -0
- package/build/probe/kernel/ast.js +49 -0
- package/build/probe/kernel/config.d.ts +5 -0
- package/build/probe/kernel/config.js +209 -0
- package/build/probe/kernel/fixpoint.d.ts +6 -0
- package/build/probe/kernel/fixpoint.js +206 -0
- package/build/probe/kernel/format.d.ts +4 -0
- package/build/probe/kernel/format.js +32 -0
- package/build/probe/kernel/graph.d.ts +4 -0
- package/build/probe/kernel/graph.js +507 -0
- package/build/probe/kernel/ids.d.ts +8 -0
- package/build/probe/kernel/ids.js +66 -0
- package/build/probe/kernel/program.d.ts +8 -0
- package/build/probe/kernel/program.js +13 -0
- package/build/probe/kernel/types.d.ts +134 -0
- package/build/probe/kernel/types.js +1 -0
- package/build/probe/overlay/base/async.jsonc +13 -0
- package/build/probe/overlay/base/exceptions.jsonc +54 -0
- package/build/probe/overlay/base/resources.jsonc +57 -0
- package/build/probe/overlay/load.d.ts +18 -0
- package/build/probe/overlay/load.js +302 -0
- package/build/probe/overlay/presets/express.jsonc +25 -0
- package/build/probe/overlay/presets/node.jsonc +17 -0
- package/build/probe/resources/channel.d.ts +4 -0
- package/build/probe/resources/channel.js +798 -0
- package/build/probe/resources/value.d.ts +9 -0
- package/build/probe/resources/value.js +36 -0
- package/build/ts.d.ts +3 -0
- package/build/ts.js +3 -0
- package/build/tsconfig.d.ts +2 -0
- package/build/tsconfig.js +150 -0
- package/package.json +29 -9
- package/tsconfig.base.json +19 -0
- package/tsconfig.dev.json +13 -0
- package/tsconfig.package.json +4 -1
- package/.claude/skills/code-audit/registry-typescript.json +0 -326
- package/.editorconfig +0 -9
- package/.gitattributes +0 -2
- package/.github/dependabot.yml +0 -25
- package/.github/workflows/bump.yml +0 -27
- package/.github/workflows/dependabot.yml +0 -58
- package/.github/workflows/publish.yml +0 -42
- package/.github/workflows/templates/bump.yml +0 -9
- package/.github/workflows/templates/dependabot.yml +0 -12
- package/.github/workflows/templates/publish.yml +0 -16
- package/pnpm-workspace.yaml +0 -6
- package/src/cli/tsc.ts +0 -235
- package/src/compiler/ast.ts +0 -60
- package/src/compiler/code.ts +0 -27
- package/src/compiler/coordinator.ts +0 -284
- package/src/compiler/imports.ts +0 -185
- package/src/compiler/index.ts +0 -7
- package/src/compiler/language-service.ts +0 -121
- package/src/compiler/plugins/index.ts +0 -5
- package/src/compiler/plugins/tsc.ts +0 -6
- package/src/compiler/plugins/vite.ts +0 -91
- package/src/compiler/types.ts +0 -83
- package/src/compiler/uid.ts +0 -10
- package/src/constants.ts +0 -4
- package/src/index.ts +0 -1
- package/tests/cli/tsc.test.ts +0 -155
- package/tests/compiler/ast.test.ts +0 -131
- package/tests/compiler/code.test.ts +0 -73
- package/tests/compiler/coordinator.bench.ts +0 -101
- package/tests/compiler/coordinator.test.ts +0 -872
- package/tests/compiler/imports.test.ts +0 -167
- package/tests/compiler/language-service.test.ts +0 -90
- package/tests/compiler/plugins.test.ts +0 -172
- package/tests/compiler/uid.test.ts +0 -70
- package/tsconfig.json +0 -3
- package/vitest.config.ts +0 -14
package/.gitattributes
DELETED
package/.github/dependabot.yml
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
# To get started with Dependabot version updates, you'll need to specify which
|
|
2
|
-
# package ecosystems to update and where the package manifests are located.
|
|
3
|
-
# Please see the documentation for all configuration options:
|
|
4
|
-
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
|
|
5
|
-
|
|
6
|
-
version: 2
|
|
7
|
-
|
|
8
|
-
registries:
|
|
9
|
-
npm-npmjs:
|
|
10
|
-
token: ${{secrets.NPM_TOKEN}}
|
|
11
|
-
type: npm-registry
|
|
12
|
-
url: https://registry.npmjs.org
|
|
13
|
-
|
|
14
|
-
updates:
|
|
15
|
-
- package-ecosystem: "npm"
|
|
16
|
-
directory: "/"
|
|
17
|
-
groups:
|
|
18
|
-
production-dependencies:
|
|
19
|
-
dependency-type: "production"
|
|
20
|
-
development-dependencies:
|
|
21
|
-
dependency-type: "development"
|
|
22
|
-
registries:
|
|
23
|
-
- npm-npmjs
|
|
24
|
-
schedule:
|
|
25
|
-
interval: "daily"
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
name: bump version
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
push:
|
|
5
|
-
branches: '**' # only trigger on branches, not on tags
|
|
6
|
-
workflow_call:
|
|
7
|
-
|
|
8
|
-
concurrency:
|
|
9
|
-
group: ${{ github.workflow }}-${{ github.ref }}
|
|
10
|
-
cancel-in-progress: true
|
|
11
|
-
|
|
12
|
-
permissions:
|
|
13
|
-
contents: write
|
|
14
|
-
|
|
15
|
-
jobs:
|
|
16
|
-
bump:
|
|
17
|
-
runs-on: ubuntu-latest
|
|
18
|
-
steps:
|
|
19
|
-
- name: checkout repo
|
|
20
|
-
uses: actions/checkout@v7
|
|
21
|
-
with:
|
|
22
|
-
fetch-depth: 0
|
|
23
|
-
- name: bump version
|
|
24
|
-
uses: jpb06/bump-package@latest
|
|
25
|
-
with:
|
|
26
|
-
minor-keywords: feat,minor,refactor
|
|
27
|
-
patch-keywords: fix,chore
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
name: dependabot automerge
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
pull_request:
|
|
5
|
-
types: [opened, synchronize, labeled]
|
|
6
|
-
workflow_call:
|
|
7
|
-
secrets:
|
|
8
|
-
NPM_TOKEN:
|
|
9
|
-
required: true
|
|
10
|
-
|
|
11
|
-
concurrency:
|
|
12
|
-
group: ${{ github.workflow }}-${{ github.ref }}
|
|
13
|
-
cancel-in-progress: true
|
|
14
|
-
|
|
15
|
-
permissions:
|
|
16
|
-
contents: write
|
|
17
|
-
pull-requests: write
|
|
18
|
-
|
|
19
|
-
jobs:
|
|
20
|
-
build:
|
|
21
|
-
runs-on: ubuntu-latest
|
|
22
|
-
steps:
|
|
23
|
-
- uses: actions/checkout@v7
|
|
24
|
-
- uses: pnpm/action-setup@v6
|
|
25
|
-
name: Install pnpm
|
|
26
|
-
with:
|
|
27
|
-
run_install: false
|
|
28
|
-
version: latest
|
|
29
|
-
- uses: actions/setup-node@v6
|
|
30
|
-
with:
|
|
31
|
-
cache: 'pnpm'
|
|
32
|
-
node-version: 'latest'
|
|
33
|
-
registry-url: 'https://registry.npmjs.org'
|
|
34
|
-
- run: pnpm i && pnpm build
|
|
35
|
-
env:
|
|
36
|
-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
37
|
-
|
|
38
|
-
automerge:
|
|
39
|
-
needs: build
|
|
40
|
-
permissions:
|
|
41
|
-
pull-requests: write
|
|
42
|
-
contents: write
|
|
43
|
-
runs-on: ubuntu-latest
|
|
44
|
-
if: ${{ github.actor == 'dependabot[bot]' && github.event_name == 'pull_request' }}
|
|
45
|
-
steps:
|
|
46
|
-
- uses: dependabot/fetch-metadata@v3
|
|
47
|
-
id: metadata
|
|
48
|
-
with:
|
|
49
|
-
alert-lookup: true
|
|
50
|
-
compat-lookup: true
|
|
51
|
-
github-token: ${{ secrets.GITHUB_TOKEN }}
|
|
52
|
-
- name: Approve and merge Dependabot PR
|
|
53
|
-
run: |
|
|
54
|
-
gh pr review --approve "$PR_URL"
|
|
55
|
-
gh pr merge --squash --auto "$PR_URL"
|
|
56
|
-
env:
|
|
57
|
-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
58
|
-
PR_URL: ${{ github.event.pull_request.html_url }}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
name: publish to npm
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
release:
|
|
5
|
-
types: [published]
|
|
6
|
-
workflow_call:
|
|
7
|
-
secrets:
|
|
8
|
-
NPM_TOKEN:
|
|
9
|
-
required: true
|
|
10
|
-
workflow_dispatch:
|
|
11
|
-
workflow_run:
|
|
12
|
-
workflows: [bump version]
|
|
13
|
-
types:
|
|
14
|
-
- completed
|
|
15
|
-
|
|
16
|
-
concurrency:
|
|
17
|
-
group: ${{ github.workflow }}-${{ github.ref }}
|
|
18
|
-
cancel-in-progress: true
|
|
19
|
-
|
|
20
|
-
jobs:
|
|
21
|
-
build:
|
|
22
|
-
runs-on: ubuntu-latest
|
|
23
|
-
permissions:
|
|
24
|
-
contents: read
|
|
25
|
-
id-token: write
|
|
26
|
-
steps:
|
|
27
|
-
- uses: actions/checkout@v7
|
|
28
|
-
- uses: pnpm/action-setup@v6
|
|
29
|
-
name: Install pnpm
|
|
30
|
-
with:
|
|
31
|
-
run_install: false
|
|
32
|
-
version: latest
|
|
33
|
-
- uses: actions/setup-node@v6
|
|
34
|
-
with:
|
|
35
|
-
cache: 'pnpm'
|
|
36
|
-
node-version: 'latest'
|
|
37
|
-
registry-url: 'https://registry.npmjs.org'
|
|
38
|
-
- run: pnpm i
|
|
39
|
-
env:
|
|
40
|
-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
41
|
-
- run: pnpm build
|
|
42
|
-
- run: pnpm publish --no-git-checks
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
name: publish to npm
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
release:
|
|
5
|
-
types: [published]
|
|
6
|
-
workflow_dispatch:
|
|
7
|
-
workflow_run:
|
|
8
|
-
workflows: [bump version]
|
|
9
|
-
types:
|
|
10
|
-
- completed
|
|
11
|
-
|
|
12
|
-
jobs:
|
|
13
|
-
publish:
|
|
14
|
-
secrets:
|
|
15
|
-
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
16
|
-
uses: esportsplus/typescript/.github/workflows/publish.yml@main
|
package/pnpm-workspace.yaml
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
# Approve dependency build scripts (pnpm errors on unapproved ones during install/publish) and trust
|
|
2
|
-
# our own scope so freshly published first-party deps bypass the minimumReleaseAge gate.
|
|
3
|
-
allowBuilds:
|
|
4
|
-
esbuild: true
|
|
5
|
-
minimumReleaseAgeExclude:
|
|
6
|
-
- '@esportsplus/*'
|
package/src/cli/tsc.ts
DELETED
|
@@ -1,235 +0,0 @@
|
|
|
1
|
-
import type { Plugin, SharedContext } from '~/compiler/types';
|
|
2
|
-
import { createRequire } from 'module';
|
|
3
|
-
import { PACKAGE_NAME } from '~/constants';
|
|
4
|
-
import { pathToFileURL } from 'url';
|
|
5
|
-
import { spawn } from 'child_process';
|
|
6
|
-
|
|
7
|
-
import coordinator from '~/compiler/coordinator';
|
|
8
|
-
import path from 'path';
|
|
9
|
-
import ts from 'typescript';
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
type PluginConfig = {
|
|
13
|
-
transform: string;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const BACKSLASH_REGEX = /\\/g;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
let require = createRequire(import.meta.url),
|
|
21
|
-
skipFlags = new Set(['--help', '--init', '--noEmit', '--showConfig', '--version', '-h', '-noEmit', '-v']);
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
async function build(config: object, tsconfig: string, pluginConfigs: PluginConfig[]): Promise<void> {
|
|
25
|
-
let root = path.dirname(path.resolve(tsconfig)),
|
|
26
|
-
parsed = ts.parseJsonConfigFileContent(config, ts.sys, root);
|
|
27
|
-
|
|
28
|
-
if (parsed.errors.length > 0) {
|
|
29
|
-
for (let i = 0, n = parsed.errors.length; i < n; i++) {
|
|
30
|
-
console.error(
|
|
31
|
-
ts.flattenDiagnosticMessageText(parsed.errors[i].messageText, '\n')
|
|
32
|
-
);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
process.exit(1);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
let plugins = await loadPlugins(pluginConfigs, root);
|
|
39
|
-
|
|
40
|
-
let program = ts.createProgram(parsed.fileNames, parsed.options),
|
|
41
|
-
shared: SharedContext = new Map(),
|
|
42
|
-
transformedFiles = new Map<string, string>();
|
|
43
|
-
|
|
44
|
-
for (let i = 0, n = parsed.fileNames.length; i < n; i++) {
|
|
45
|
-
let fileName = parsed.fileNames[i],
|
|
46
|
-
sourceFile = program.getSourceFile(fileName);
|
|
47
|
-
|
|
48
|
-
if (!sourceFile) {
|
|
49
|
-
continue;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
let result = coordinator.transform(
|
|
53
|
-
plugins,
|
|
54
|
-
sourceFile.getFullText(),
|
|
55
|
-
sourceFile,
|
|
56
|
-
program,
|
|
57
|
-
root,
|
|
58
|
-
shared
|
|
59
|
-
);
|
|
60
|
-
|
|
61
|
-
if (result.changed) {
|
|
62
|
-
transformedFiles.set(normalizePath(fileName), result.code);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
if (transformedFiles.size > 0) {
|
|
67
|
-
let customHost = ts.createCompilerHost(parsed.options),
|
|
68
|
-
originalGetSourceFile = customHost.getSourceFile.bind(customHost),
|
|
69
|
-
originalReadFile = customHost.readFile.bind(customHost);
|
|
70
|
-
|
|
71
|
-
customHost.getSourceFile = (
|
|
72
|
-
fileName: string,
|
|
73
|
-
languageVersion: ts.ScriptTarget,
|
|
74
|
-
onError?: (message: string) => void,
|
|
75
|
-
shouldCreateNewSourceFile?: boolean
|
|
76
|
-
): ts.SourceFile | undefined => {
|
|
77
|
-
let transformed = transformedFiles.get(normalizePath(fileName));
|
|
78
|
-
|
|
79
|
-
if (transformed) {
|
|
80
|
-
return ts.createSourceFile(fileName, transformed, languageVersion, true);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
return originalGetSourceFile(fileName, languageVersion, onError, shouldCreateNewSourceFile);
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
customHost.readFile = (fileName: string): string | undefined => {
|
|
87
|
-
return transformedFiles.get(normalizePath(fileName)) ?? originalReadFile(fileName);
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
program = ts.createProgram(parsed.fileNames, parsed.options, customHost);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
let { diagnostics, emitSkipped } = program.emit();
|
|
94
|
-
|
|
95
|
-
diagnostics = ts.getPreEmitDiagnostics(program).concat(diagnostics);
|
|
96
|
-
|
|
97
|
-
if (diagnostics.length > 0) {
|
|
98
|
-
console.error(
|
|
99
|
-
ts.formatDiagnosticsWithColorAndContext(diagnostics, {
|
|
100
|
-
getCanonicalFileName: (fileName) => fileName,
|
|
101
|
-
getCurrentDirectory: () => root,
|
|
102
|
-
getNewLine: () => '\n'
|
|
103
|
-
})
|
|
104
|
-
);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
if (emitSkipped) {
|
|
108
|
-
process.exit(1);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
return runTscAlias(process.argv.slice(2)).then((code) => process.exit(code));
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
function isPlugin(value: unknown): value is Plugin {
|
|
115
|
-
return typeof value === 'object' && value !== null && 'transform' in value && typeof (value as Plugin).transform === 'function';
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
async function loadPlugins(configs: PluginConfig[], root: string): Promise<Plugin[]> {
|
|
119
|
-
let plugins: Plugin[] = [],
|
|
120
|
-
promises: Promise<void>[] = [];
|
|
121
|
-
|
|
122
|
-
for (let i = 0, n = configs.length; i < n; i++) {
|
|
123
|
-
let config = configs[i],
|
|
124
|
-
pluginPath = config.transform;
|
|
125
|
-
|
|
126
|
-
if (pluginPath.startsWith('.')) {
|
|
127
|
-
pluginPath = pathToFileURL(path.resolve(root, pluginPath)).href;
|
|
128
|
-
}
|
|
129
|
-
else {
|
|
130
|
-
pluginPath = pathToFileURL(require.resolve(pluginPath, { paths: [root] })).href;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
promises.push(
|
|
134
|
-
import(pluginPath).then((module) => {
|
|
135
|
-
let plugin = module.default ?? module;
|
|
136
|
-
|
|
137
|
-
if (typeof plugin === 'function') {
|
|
138
|
-
plugin = plugin();
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
if (Array.isArray(plugin)) {
|
|
142
|
-
for (let j = 0, m = plugin.length; j < m; j++) {
|
|
143
|
-
if (isPlugin(plugin[j])) {
|
|
144
|
-
plugins.push(plugin[j]);
|
|
145
|
-
}
|
|
146
|
-
else {
|
|
147
|
-
console.error(`${PACKAGE_NAME}: plugin ${config.transform}[${j}] uses an invalid plugin format`);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
return;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
if (!isPlugin(plugin)) {
|
|
155
|
-
console.error(`${PACKAGE_NAME}: plugin ${config.transform} uses an invalid plugin format, expected { transform: Function } or Plugin[]`);
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
plugins.push(plugin);
|
|
160
|
-
})
|
|
161
|
-
);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
await Promise.all(promises);
|
|
165
|
-
|
|
166
|
-
return plugins;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
function main(): void {
|
|
170
|
-
let tsconfig = ts.findConfigFile(process.cwd(), ts.sys.fileExists, 'tsconfig.json');
|
|
171
|
-
|
|
172
|
-
if (!tsconfig) {
|
|
173
|
-
return passthrough();
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
let { config, error } = ts.readConfigFile(tsconfig, ts.sys.readFile);
|
|
177
|
-
|
|
178
|
-
if (error) {
|
|
179
|
-
return passthrough();
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
let pluginConfigs = config?.compilerOptions?.plugins?.filter(
|
|
183
|
-
(p: unknown) => typeof p === 'object' && p !== null && 'transform' in p
|
|
184
|
-
) ?? [];
|
|
185
|
-
|
|
186
|
-
if (pluginConfigs.length === 0) {
|
|
187
|
-
return passthrough();
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
console.log(`${PACKAGE_NAME}: found ${pluginConfigs.length} transformer plugin(s), using coordinated build...`);
|
|
191
|
-
|
|
192
|
-
build(config, tsconfig, pluginConfigs).catch((err) => {
|
|
193
|
-
console.error(`${PACKAGE_NAME}: ${err}`);
|
|
194
|
-
process.exit(1);
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
function normalizePath(fileName: string): string {
|
|
199
|
-
return path.resolve(fileName).replace(BACKSLASH_REGEX, '/');
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
function passthrough(): void {
|
|
203
|
-
let args = process.argv.slice(2);
|
|
204
|
-
|
|
205
|
-
spawn(process.execPath, [require.resolve('typescript/lib/tsc.js'), ...args], { stdio: 'inherit' })
|
|
206
|
-
.on('exit', async (code) => {
|
|
207
|
-
if (code === 0) {
|
|
208
|
-
code = await runTscAlias(args);
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
process.exit(code ?? 0);
|
|
212
|
-
});
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
function runTscAlias(args: string[]): Promise<number> {
|
|
216
|
-
for (let i = 0, n = args.length; i < n; i++) {
|
|
217
|
-
if (skipFlags.has(args[i])) {
|
|
218
|
-
return Promise.resolve(0);
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
return new Promise((resolve) => {
|
|
223
|
-
let child = spawn(process.execPath, [require.resolve('tsc-alias/dist/bin/index.js'), ...args], { stdio: 'inherit' });
|
|
224
|
-
|
|
225
|
-
child.on('exit', (code) => resolve(code ?? 0));
|
|
226
|
-
});
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
if (process.env.VITEST === undefined) {
|
|
231
|
-
main();
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
export { build, isPlugin, loadPlugins, normalizePath, runTscAlias };
|
package/src/compiler/ast.ts
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import type { Range } from './types';
|
|
2
|
-
import { ts } from '~/index';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const expression = {
|
|
6
|
-
name: (node: ts.Expression): string | null => {
|
|
7
|
-
if (ts.isIdentifier(node)) {
|
|
8
|
-
return node.text;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
if (ts.isPropertyAccessExpression(node)) {
|
|
12
|
-
return property.path(node);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
return null;
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
const inRange = (ranges: Range[], start: number, end: number): boolean => {
|
|
20
|
-
for (let i = 0, n = ranges.length; i < n; i++) {
|
|
21
|
-
let r = ranges[i];
|
|
22
|
-
|
|
23
|
-
if (start >= r.start && end <= r.end) {
|
|
24
|
-
return true;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return false;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
const property = {
|
|
32
|
-
path: (node: ts.Expression): string | null => {
|
|
33
|
-
let current: ts.Node = node,
|
|
34
|
-
parts: string[] = [];
|
|
35
|
-
|
|
36
|
-
while (ts.isPropertyAccessExpression(current)) {
|
|
37
|
-
parts.push(current.name.text);
|
|
38
|
-
current = current.expression;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
if (ts.isIdentifier(current)) {
|
|
42
|
-
parts.push(current.text);
|
|
43
|
-
return parts.reverse().join('.');
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return null;
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
const test = (node: ts.Node, fn: (n: ts.Node) => boolean): boolean => {
|
|
51
|
-
if (fn(node)) {
|
|
52
|
-
return true;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return !!ts.forEachChild(node, child => test(child, fn) || undefined);
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
export default { expression, inRange, property, test };
|
|
60
|
-
export type { Range };
|
package/src/compiler/code.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
const SINGLE_QUOTE_REGEX = /'/g;
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const code = (literals: TemplateStringsArray, ...values: unknown[]): string => {
|
|
5
|
-
let buffer = '';
|
|
6
|
-
|
|
7
|
-
for (let i = 0, n = literals.length; i < n; i++) {
|
|
8
|
-
buffer += literals[i];
|
|
9
|
-
|
|
10
|
-
let value = values[i];
|
|
11
|
-
|
|
12
|
-
if (value == null || value === false) {
|
|
13
|
-
value = '';
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
buffer += value;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
return buffer;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
code.escape = (str: string): string => {
|
|
23
|
-
return str.replace(SINGLE_QUOTE_REGEX, "\\'");
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
export default code;
|