svelte-ag 1.1.0 → 1.1.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/package.json +5 -8
- package/dist/scripts/resolve-paths/index.d.ts +0 -31
- package/dist/scripts/resolve-paths/index.d.ts.map +0 -1
- package/dist/scripts/resolve-paths/index.js +0 -549
- package/dist/scripts/resolve-paths/log.d.ts +0 -4
- package/dist/scripts/resolve-paths/log.d.ts.map +0 -1
- package/dist/scripts/resolve-paths/log.js +0 -18
- package/dist/scripts/resolve-paths/resolve-paths.unit.test.d.ts +0 -2
- package/dist/scripts/resolve-paths/resolve-paths.unit.test.d.ts.map +0 -1
- package/dist/scripts/resolve-paths/resolve-paths.unit.test.js +0 -191
- package/src/lib/scripts/resolve-paths/index.ts +0 -755
- package/src/lib/scripts/resolve-paths/log.ts +0 -26
- package/src/lib/scripts/resolve-paths/resolve-paths.unit.test.ts +0 -244
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "svelte-ag",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "Useful svelte components",
|
|
5
5
|
"bugs": "https://github.com/ageorgeh/svelte-ag/issues",
|
|
6
6
|
"repository": {
|
|
@@ -19,9 +19,6 @@
|
|
|
19
19
|
"./styles/*": "./dist/styles/*",
|
|
20
20
|
"./package.json": "./package.json"
|
|
21
21
|
},
|
|
22
|
-
"bin": {
|
|
23
|
-
"resolve-paths": "dist/scripts/resolve-paths/index.js"
|
|
24
|
-
},
|
|
25
22
|
"files": [
|
|
26
23
|
"./src/lib",
|
|
27
24
|
"./dist"
|
|
@@ -46,7 +43,7 @@
|
|
|
46
43
|
"dependencies": {
|
|
47
44
|
"@dnd-kit-svelte/svelte": "^0.1.6",
|
|
48
45
|
"@floating-ui/dom": "^1.7.6",
|
|
49
|
-
"bits-ui": "^2.
|
|
46
|
+
"bits-ui": "^2.17.2",
|
|
50
47
|
"clsx": "^2.1.1",
|
|
51
48
|
"dequal": "^2.0.3",
|
|
52
49
|
"devalue": "^5.6.4",
|
|
@@ -65,7 +62,7 @@
|
|
|
65
62
|
"devDependencies": {
|
|
66
63
|
"@actions/languageserver": "^0.3.51",
|
|
67
64
|
"@eslint/js": "^10.0.1",
|
|
68
|
-
"@iconify/json": "^2.2.
|
|
65
|
+
"@iconify/json": "^2.2.459",
|
|
69
66
|
"@iconify/tailwind4": "^1.2.3",
|
|
70
67
|
"@iconify/types": "^2.0.0",
|
|
71
68
|
"@internationalized/date": "^3.12.0",
|
|
@@ -88,14 +85,14 @@
|
|
|
88
85
|
"prettier": "^3.8.1",
|
|
89
86
|
"prettier-plugin-packagejson": "^3.0.1",
|
|
90
87
|
"prettier-plugin-svelte": "^3.5.1",
|
|
91
|
-
"rolldown": "1.0.0-rc.
|
|
88
|
+
"rolldown": "1.0.0-rc.13",
|
|
92
89
|
"rolldown-plugin-dts": "^0.23.2",
|
|
93
90
|
"rollup-plugin-svelte": "^7.2.3",
|
|
94
91
|
"semantic-release": "^25.0.3",
|
|
95
92
|
"svelte": "^5.55.1",
|
|
96
93
|
"svelte-check": "^4.4.6",
|
|
97
94
|
"svelte-preprocess": "^6.0.3",
|
|
98
|
-
"svelte2tsx": "^0.7.
|
|
95
|
+
"svelte2tsx": "^0.7.53",
|
|
99
96
|
"tailwindcss": "4.2.2",
|
|
100
97
|
"tsdown": "^0.21.7",
|
|
101
98
|
"tsx": "^4.21.0",
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
//#region dist/scripts/resolve-paths/index.d.ts
|
|
2
|
-
interface ResolvePathsProject {
|
|
3
|
-
tsconfigPath: string;
|
|
4
|
-
rootDir: string;
|
|
5
|
-
srcDir: string;
|
|
6
|
-
distDir: string;
|
|
7
|
-
}
|
|
8
|
-
interface ResolvePathsOptions {
|
|
9
|
-
cwd?: string;
|
|
10
|
-
excludeAliases?: string[];
|
|
11
|
-
inputs?: string[];
|
|
12
|
-
}
|
|
13
|
-
interface ResolvePathsWatcher {
|
|
14
|
-
close(): void;
|
|
15
|
-
projects: ResolvePathsProject[];
|
|
16
|
-
}
|
|
17
|
-
interface CliOptions {
|
|
18
|
-
excludeAliases: string[];
|
|
19
|
-
inputs: string[];
|
|
20
|
-
watchMode: boolean;
|
|
21
|
-
}
|
|
22
|
-
declare function buildProject(project: ResolvePathsProject, options?: ResolvePathsOptions): Promise<void>;
|
|
23
|
-
declare function findProjects(options?: ResolvePathsOptions): Promise<ResolvePathsProject[]>;
|
|
24
|
-
declare function buildProjects(options?: ResolvePathsOptions): Promise<ResolvePathsProject[]>;
|
|
25
|
-
declare function watchProjects(options?: ResolvePathsOptions): Promise<ResolvePathsWatcher>;
|
|
26
|
-
declare function parseCliArgs(args: string[]): CliOptions;
|
|
27
|
-
declare function isDirectExecution(entryPath?: string, moduleUrl?: string): boolean;
|
|
28
|
-
declare function main(args?: string[]): Promise<void>;
|
|
29
|
-
//#endregion
|
|
30
|
-
export { ResolvePathsOptions, ResolvePathsProject, ResolvePathsWatcher, buildProject, buildProjects, findProjects, isDirectExecution, main, parseCliArgs, watchProjects };
|
|
31
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":["ResolvePathsProject","tsconfigPath","rootDir","srcDir","distDir","ResolvePathsOptions","cwd","excludeAliases","inputs","ResolvePathsWatcher","close","projects","CliOptions","watchMode","buildProject","Promise","project","options","findProjects","buildProjects","watchProjects","parseCliArgs","args","isDirectExecution","entryPath","moduleUrl","main"],"sources":["../../home/runner/work/svelte-ag/svelte-ag/dist/scripts/resolve-paths/index.d.ts"],"mappings":";UAAiBA,mBAAAA;EACbC,YAAAA;EACAC,OAAAA;EACAC,MAAAA;EACAC,OAAAA;AAAAA;AAAAA,UAEaC,mBAAAA;EACbC,GAAAA;EACAC,cAAAA;EACAC,MAAAA;AAAAA;AAAAA,UAEaC,mBAAAA;EACbC,KAAAA;EACAC,QAAAA,EAAUX,mBAAAA;AAAAA;AAAAA,UAEJY,UAAAA;EACNL,cAAAA;EACAC,MAAAA;EACAK,SAAAA;AAAAA;AAAAA,iBAEoBC,YAAAA,CAAaE,OAAAA,EAAShB,mBAAAA,EAAqBiB,OAAAA,GAAUZ,mBAAAA,GAAsBU,OAAAA;AAAAA,iBAC3EG,YAAAA,CAAaD,OAAAA,GAAUZ,mBAAAA,GAAsBU,OAAAA,CAAQf,mBAAAA;AAAAA,iBACrDmB,aAAAA,CAAcF,OAAAA,GAAUZ,mBAAAA,GAAsBU,OAAAA,CAAQf,mBAAAA;AAAAA,iBACtDoB,aAAAA,CAAcH,OAAAA,GAAUZ,mBAAAA,GAAsBU,OAAAA,CAAQN,mBAAAA;AAAAA,iBACtDY,YAAAA,CAAaC,IAAAA,aAAiBV,UAAAA;AAAAA,iBAC9BW,iBAAAA,CAAkBC,SAAAA,WAAoBC,SAAAA;AAAAA,iBACtCC,IAAAA,CAAKJ,IAAAA,cAAkBP,OAAAA"}
|
|
@@ -1,549 +0,0 @@
|
|
|
1
|
-
import { cp, glob, mkdir, readFile, readdir, rename, rm, stat, writeFile } from 'node:fs/promises';
|
|
2
|
-
import { realpathSync, watch } from 'node:fs';
|
|
3
|
-
import { basename, dirname, isAbsolute, join, relative, resolve } from 'node:path';
|
|
4
|
-
import { fileURLToPath } from 'node:url';
|
|
5
|
-
import { prepareSingleFileReplaceTscAliasPaths, replaceTscAliasPaths } from 'tsc-alias';
|
|
6
|
-
import { loadConfig, prepareConfig } from 'tsc-alias/dist/helpers/config.js';
|
|
7
|
-
import { Output, TrieNode } from 'tsc-alias/dist/utils/index.js';
|
|
8
|
-
import { exists } from 'ts-ag';
|
|
9
|
-
import { logError, logInfo } from './log.js';
|
|
10
|
-
const DEFAULT_INPUTS = ['tsconfig.json'];
|
|
11
|
-
const GLOB_EXCLUDES = ['**/node_modules/**', '**/.git/**', '**/.svelte-kit/**', '**/dist/**'];
|
|
12
|
-
const TEMPORARY_WATCH_FILE_SUFFIXES = ['~', '.swp', '.swo', '.tmp', '.temp', '.bak', '.orig'];
|
|
13
|
-
const REPLACEABLE_FILE_EXTENSIONS = {
|
|
14
|
-
inputGlob: '{ts,tsx,js,jsx,mjs,cjs,svelte,d.{mts,cts,ts,tsx}}',
|
|
15
|
-
outputCheck: [
|
|
16
|
-
'ts',
|
|
17
|
-
'tsx',
|
|
18
|
-
'js',
|
|
19
|
-
'jsx',
|
|
20
|
-
'mjs',
|
|
21
|
-
'cjs',
|
|
22
|
-
'svelte',
|
|
23
|
-
'json',
|
|
24
|
-
'mts',
|
|
25
|
-
'cts',
|
|
26
|
-
'd.ts',
|
|
27
|
-
'd.tsx',
|
|
28
|
-
'd.mts',
|
|
29
|
-
'd.cts'
|
|
30
|
-
]
|
|
31
|
-
};
|
|
32
|
-
function formatPath(targetPath, cwd = process.cwd()) {
|
|
33
|
-
return relative(cwd, targetPath) || '.';
|
|
34
|
-
}
|
|
35
|
-
function normalizeWatchPathSeparators(filePath) {
|
|
36
|
-
return filePath.replaceAll('\\', '/');
|
|
37
|
-
}
|
|
38
|
-
function isTemporaryWatchPath(sourceRelativePath) {
|
|
39
|
-
const normalizedSourceRelativePath = normalizeWatchPathSeparators(sourceRelativePath);
|
|
40
|
-
const fileName = basename(normalizedSourceRelativePath);
|
|
41
|
-
return (TEMPORARY_WATCH_FILE_SUFFIXES.some((suffix) => fileName.endsWith(suffix)) ||
|
|
42
|
-
fileName.startsWith('.#') ||
|
|
43
|
-
(fileName.startsWith('#') && fileName.endsWith('#')));
|
|
44
|
-
}
|
|
45
|
-
function getCanonicalWatchPathCandidates(sourceRelativePath) {
|
|
46
|
-
const normalizedSourceRelativePath = normalizeWatchPathSeparators(sourceRelativePath);
|
|
47
|
-
const fileName = basename(normalizedSourceRelativePath);
|
|
48
|
-
const parentDirectory = dirname(normalizedSourceRelativePath);
|
|
49
|
-
const parentPrefix = parentDirectory === '.' ? '' : `${parentDirectory}/`;
|
|
50
|
-
const canonicalFileNames = new Set();
|
|
51
|
-
if (fileName.endsWith('~') && fileName.length > 1) {
|
|
52
|
-
canonicalFileNames.add(fileName.slice(0, -1));
|
|
53
|
-
}
|
|
54
|
-
for (const suffix of TEMPORARY_WATCH_FILE_SUFFIXES.filter((value) => value !== '~')) {
|
|
55
|
-
if (fileName.endsWith(suffix) && fileName.length > suffix.length) {
|
|
56
|
-
canonicalFileNames.add(fileName.slice(0, -suffix.length));
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
if (fileName.startsWith('.#') && fileName.length > 2) {
|
|
60
|
-
canonicalFileNames.add(fileName.slice(2));
|
|
61
|
-
}
|
|
62
|
-
if (fileName.startsWith('#') && fileName.endsWith('#') && fileName.length > 2) {
|
|
63
|
-
canonicalFileNames.add(fileName.slice(1, -1));
|
|
64
|
-
}
|
|
65
|
-
return [...canonicalFileNames].map((candidate) => `${parentPrefix}${candidate}`);
|
|
66
|
-
}
|
|
67
|
-
async function resolveWatchedSourcePath(project, sourceRelativePath) {
|
|
68
|
-
const normalizedSourceRelativePath = normalizeWatchPathSeparators(sourceRelativePath);
|
|
69
|
-
const temporaryPath = isTemporaryWatchPath(normalizedSourceRelativePath);
|
|
70
|
-
const candidates = temporaryPath
|
|
71
|
-
? [...getCanonicalWatchPathCandidates(normalizedSourceRelativePath), normalizedSourceRelativePath]
|
|
72
|
-
: [normalizedSourceRelativePath, ...getCanonicalWatchPathCandidates(normalizedSourceRelativePath)];
|
|
73
|
-
for (const candidate of [...new Set(candidates)]) {
|
|
74
|
-
const sourcePath = resolve(project.srcDir, candidate);
|
|
75
|
-
const normalizedRelativePath = relative(project.srcDir, sourcePath);
|
|
76
|
-
if (normalizedRelativePath.startsWith('..') || isAbsolute(normalizedRelativePath)) {
|
|
77
|
-
continue;
|
|
78
|
-
}
|
|
79
|
-
if (await exists(sourcePath)) {
|
|
80
|
-
return normalizeWatchPathSeparators(normalizedRelativePath);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
return temporaryPath ? undefined : normalizedSourceRelativePath;
|
|
84
|
-
}
|
|
85
|
-
async function resolveDirectInput(input, cwd) {
|
|
86
|
-
const absoluteInputPath = isAbsolute(input) ? input : resolve(cwd, input);
|
|
87
|
-
if (!(await exists(absoluteInputPath))) {
|
|
88
|
-
return [];
|
|
89
|
-
}
|
|
90
|
-
const inputStats = await stat(absoluteInputPath);
|
|
91
|
-
if (inputStats.isDirectory()) {
|
|
92
|
-
const nestedTsconfigPath = resolve(absoluteInputPath, 'tsconfig.json');
|
|
93
|
-
return (await exists(nestedTsconfigPath)) ? [nestedTsconfigPath] : [];
|
|
94
|
-
}
|
|
95
|
-
return [absoluteInputPath];
|
|
96
|
-
}
|
|
97
|
-
async function expandInput(input, cwd) {
|
|
98
|
-
const directMatches = await resolveDirectInput(input, cwd);
|
|
99
|
-
if (directMatches.length > 0) {
|
|
100
|
-
return directMatches;
|
|
101
|
-
}
|
|
102
|
-
const matches = await Array.fromAsync(glob(input, {
|
|
103
|
-
cwd,
|
|
104
|
-
exclude: GLOB_EXCLUDES
|
|
105
|
-
}));
|
|
106
|
-
return matches.map((match) => resolve(cwd, match));
|
|
107
|
-
}
|
|
108
|
-
function normalizeAliasPrefix(alias) {
|
|
109
|
-
return alias.replace(/\/\*$/, '').replace(/\/+$/, '');
|
|
110
|
-
}
|
|
111
|
-
function normalizeExcludedAliases(excludedAliases = []) {
|
|
112
|
-
return [...new Set(excludedAliases.map(normalizeAliasPrefix).filter(Boolean))];
|
|
113
|
-
}
|
|
114
|
-
function createTemporaryPath(rootDir, prefix) {
|
|
115
|
-
return resolve(rootDir, `.${prefix}-${process.pid}-${Date.now()}-${Math.random().toString(36).slice(2, 8)}.tmp`);
|
|
116
|
-
}
|
|
117
|
-
function createSilentOutput() {
|
|
118
|
-
return new Output(false, false);
|
|
119
|
-
}
|
|
120
|
-
async function createFilteredAliasTrie(project, excludedAliases, outDir) {
|
|
121
|
-
if (excludedAliases.length === 0) {
|
|
122
|
-
return undefined;
|
|
123
|
-
}
|
|
124
|
-
const normalizedExcludedAliases = new Set(excludedAliases.map(normalizeAliasPrefix).filter(Boolean));
|
|
125
|
-
const output = createSilentOutput();
|
|
126
|
-
const loadedConfig = loadConfig(project.tsconfigPath, output);
|
|
127
|
-
if (!loadedConfig.paths) {
|
|
128
|
-
return undefined;
|
|
129
|
-
}
|
|
130
|
-
const filteredPaths = Object.fromEntries(Object.entries(loadedConfig.paths).filter(([alias]) => !normalizedExcludedAliases.has(normalizeAliasPrefix(alias))));
|
|
131
|
-
const preparedConfig = await prepareConfig({
|
|
132
|
-
configFile: project.tsconfigPath,
|
|
133
|
-
fileExtensions: {
|
|
134
|
-
inputGlob: REPLACEABLE_FILE_EXTENSIONS.inputGlob,
|
|
135
|
-
outputCheck: [...REPLACEABLE_FILE_EXTENSIONS.outputCheck]
|
|
136
|
-
},
|
|
137
|
-
outDir,
|
|
138
|
-
output
|
|
139
|
-
});
|
|
140
|
-
return TrieNode.buildAliasTrie(preparedConfig, filteredPaths);
|
|
141
|
-
}
|
|
142
|
-
function isReplaceableOutputFile(filePath) {
|
|
143
|
-
const normalizedFilePath = filePath.toLowerCase();
|
|
144
|
-
return REPLACEABLE_FILE_EXTENSIONS.outputCheck.some((extension) => normalizedFilePath.endsWith(`.${extension.toLowerCase()}`));
|
|
145
|
-
}
|
|
146
|
-
async function createSingleFileAliasReplacer(project, excludedAliases) {
|
|
147
|
-
return prepareSingleFileReplaceTscAliasPaths({
|
|
148
|
-
aliasTrie: await createFilteredAliasTrie(project, excludedAliases, project.distDir),
|
|
149
|
-
configFile: project.tsconfigPath,
|
|
150
|
-
outDir: project.distDir,
|
|
151
|
-
fileExtensions: {
|
|
152
|
-
inputGlob: REPLACEABLE_FILE_EXTENSIONS.inputGlob,
|
|
153
|
-
outputCheck: [...REPLACEABLE_FILE_EXTENSIONS.outputCheck]
|
|
154
|
-
}
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
async function resolveAliases(project, outDir, options = {}) {
|
|
158
|
-
await replaceTscAliasPaths({
|
|
159
|
-
aliasTrie: await createFilteredAliasTrie(project, options.excludeAliases ?? [], outDir),
|
|
160
|
-
configFile: project.tsconfigPath,
|
|
161
|
-
outDir,
|
|
162
|
-
fileExtensions: {
|
|
163
|
-
inputGlob: REPLACEABLE_FILE_EXTENSIONS.inputGlob,
|
|
164
|
-
outputCheck: [...REPLACEABLE_FILE_EXTENSIONS.outputCheck]
|
|
165
|
-
}
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
async function copyProjectSource(project, outDir) {
|
|
169
|
-
await rm(outDir, {
|
|
170
|
-
force: true,
|
|
171
|
-
recursive: true
|
|
172
|
-
});
|
|
173
|
-
await mkdir(dirname(outDir), { recursive: true });
|
|
174
|
-
await cp(project.srcDir, outDir, {
|
|
175
|
-
force: true,
|
|
176
|
-
recursive: true
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
async function collectProjectTree(rootDir, currentDir = rootDir) {
|
|
180
|
-
if (!(await exists(currentDir))) {
|
|
181
|
-
return [];
|
|
182
|
-
}
|
|
183
|
-
const entries = await readdir(currentDir, { withFileTypes: true });
|
|
184
|
-
const paths = [];
|
|
185
|
-
for (const entry of entries) {
|
|
186
|
-
const entryPath = join(currentDir, entry.name);
|
|
187
|
-
const relativePath = relative(rootDir, entryPath);
|
|
188
|
-
paths.push(relativePath);
|
|
189
|
-
if (entry.isDirectory()) {
|
|
190
|
-
paths.push(...(await collectProjectTree(rootDir, entryPath)));
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
return paths;
|
|
194
|
-
}
|
|
195
|
-
async function publishStagedProject(stageDir, distDir) {
|
|
196
|
-
const stagedPaths = await collectProjectTree(stageDir);
|
|
197
|
-
const stagedPathSet = new Set(stagedPaths);
|
|
198
|
-
for (const relativePath of stagedPaths
|
|
199
|
-
.filter((path) => path !== '')
|
|
200
|
-
.sort((left, right) => left.localeCompare(right))) {
|
|
201
|
-
const stagedPath = resolve(stageDir, relativePath);
|
|
202
|
-
const distPath = resolve(distDir, relativePath);
|
|
203
|
-
const stagedStats = await stat(stagedPath);
|
|
204
|
-
if (stagedStats.isDirectory()) {
|
|
205
|
-
await mkdir(distPath, { recursive: true });
|
|
206
|
-
continue;
|
|
207
|
-
}
|
|
208
|
-
await mkdir(dirname(distPath), { recursive: true });
|
|
209
|
-
await rename(stagedPath, distPath);
|
|
210
|
-
}
|
|
211
|
-
if (!(await exists(distDir))) {
|
|
212
|
-
return;
|
|
213
|
-
}
|
|
214
|
-
const distPaths = await collectProjectTree(distDir);
|
|
215
|
-
for (const relativePath of distPaths.sort((left, right) => right.length - left.length || right.localeCompare(left))) {
|
|
216
|
-
if (!stagedPathSet.has(relativePath)) {
|
|
217
|
-
await rm(resolve(distDir, relativePath), {
|
|
218
|
-
force: true,
|
|
219
|
-
recursive: true
|
|
220
|
-
});
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
async function resolveFileContents(project, distPath, sourceContents, excludedAliases) {
|
|
225
|
-
if (!isReplaceableOutputFile(distPath)) {
|
|
226
|
-
return sourceContents;
|
|
227
|
-
}
|
|
228
|
-
const resolveAliasesInFile = await createSingleFileAliasReplacer(project, excludedAliases);
|
|
229
|
-
return resolveAliasesInFile({
|
|
230
|
-
fileContents: sourceContents,
|
|
231
|
-
filePath: distPath
|
|
232
|
-
});
|
|
233
|
-
}
|
|
234
|
-
async function publishFileAtomically(project, sourcePath, distPath, excludedAliases) {
|
|
235
|
-
const tempPath = createTemporaryPath(dirname(distPath), basename(distPath));
|
|
236
|
-
await mkdir(dirname(distPath), { recursive: true });
|
|
237
|
-
if (isReplaceableOutputFile(distPath)) {
|
|
238
|
-
const sourceContents = await readFile(sourcePath, 'utf8');
|
|
239
|
-
const resolvedContents = await resolveFileContents(project, distPath, sourceContents, excludedAliases);
|
|
240
|
-
await writeFile(tempPath, resolvedContents, 'utf8');
|
|
241
|
-
}
|
|
242
|
-
else {
|
|
243
|
-
await cp(sourcePath, tempPath, { force: true });
|
|
244
|
-
}
|
|
245
|
-
await rename(tempPath, distPath);
|
|
246
|
-
}
|
|
247
|
-
async function syncProjectSourcePath(project, sourceRelativePath, excludedAliases) {
|
|
248
|
-
const sourcePath = resolve(project.srcDir, sourceRelativePath);
|
|
249
|
-
const normalizedRelativePath = relative(project.srcDir, sourcePath);
|
|
250
|
-
if (normalizedRelativePath.startsWith('..') || isAbsolute(normalizedRelativePath)) {
|
|
251
|
-
await buildProject(project, {
|
|
252
|
-
excludeAliases: excludedAliases
|
|
253
|
-
});
|
|
254
|
-
return 'rebuilt';
|
|
255
|
-
}
|
|
256
|
-
const distPath = resolve(project.distDir, normalizedRelativePath);
|
|
257
|
-
if (!(await exists(sourcePath))) {
|
|
258
|
-
await rm(distPath, {
|
|
259
|
-
force: true,
|
|
260
|
-
recursive: true
|
|
261
|
-
});
|
|
262
|
-
return 'synced';
|
|
263
|
-
}
|
|
264
|
-
const sourceStats = await stat(sourcePath);
|
|
265
|
-
if (!sourceStats.isFile()) {
|
|
266
|
-
await buildProject(project, {
|
|
267
|
-
excludeAliases: excludedAliases
|
|
268
|
-
});
|
|
269
|
-
return 'rebuilt';
|
|
270
|
-
}
|
|
271
|
-
await publishFileAtomically(project, sourcePath, distPath, excludedAliases);
|
|
272
|
-
return 'synced';
|
|
273
|
-
}
|
|
274
|
-
export async function buildProject(project, options = {}) {
|
|
275
|
-
const excludedAliases = normalizeExcludedAliases(options.excludeAliases);
|
|
276
|
-
const stageDir = createTemporaryPath(project.rootDir, basename(project.distDir));
|
|
277
|
-
try {
|
|
278
|
-
await copyProjectSource(project, stageDir);
|
|
279
|
-
await resolveAliases(project, stageDir, {
|
|
280
|
-
...options,
|
|
281
|
-
excludeAliases: excludedAliases
|
|
282
|
-
});
|
|
283
|
-
await publishStagedProject(stageDir, project.distDir);
|
|
284
|
-
}
|
|
285
|
-
finally {
|
|
286
|
-
await rm(stageDir, {
|
|
287
|
-
force: true,
|
|
288
|
-
recursive: true
|
|
289
|
-
});
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
export async function findProjects(options = {}) {
|
|
293
|
-
const cwd = options.cwd ?? process.cwd();
|
|
294
|
-
const inputs = options.inputs && options.inputs.length > 0 ? options.inputs : DEFAULT_INPUTS;
|
|
295
|
-
const resolvedTsconfigPaths = new Set();
|
|
296
|
-
for (const input of inputs) {
|
|
297
|
-
const matches = await expandInput(input, cwd);
|
|
298
|
-
if (matches.length === 0) {
|
|
299
|
-
throw new Error(`No tsconfig.json files matched "${input}" from ${formatPath(cwd, cwd)}`);
|
|
300
|
-
}
|
|
301
|
-
for (const match of matches) {
|
|
302
|
-
if (basename(match) !== 'tsconfig.json') {
|
|
303
|
-
continue;
|
|
304
|
-
}
|
|
305
|
-
resolvedTsconfigPaths.add(resolve(match));
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
const projects = await Promise.all([...resolvedTsconfigPaths]
|
|
309
|
-
.sort((left, right) => left.localeCompare(right))
|
|
310
|
-
.map(async (tsconfigPath) => {
|
|
311
|
-
const rootDir = dirname(tsconfigPath);
|
|
312
|
-
const srcDir = resolve(rootDir, 'src');
|
|
313
|
-
if (!(await exists(srcDir))) {
|
|
314
|
-
throw new Error(`Missing src directory for ${formatPath(tsconfigPath, cwd)} at ${formatPath(srcDir, cwd)}`);
|
|
315
|
-
}
|
|
316
|
-
return {
|
|
317
|
-
distDir: resolve(rootDir, 'dist'),
|
|
318
|
-
rootDir,
|
|
319
|
-
srcDir,
|
|
320
|
-
tsconfigPath
|
|
321
|
-
};
|
|
322
|
-
}));
|
|
323
|
-
if (projects.length === 0) {
|
|
324
|
-
throw new Error(`No tsconfig.json files matched: ${inputs.join(', ')}`);
|
|
325
|
-
}
|
|
326
|
-
return projects;
|
|
327
|
-
}
|
|
328
|
-
export async function buildProjects(options = {}) {
|
|
329
|
-
const cwd = options.cwd ?? process.cwd();
|
|
330
|
-
const projects = await findProjects(options);
|
|
331
|
-
await Promise.all(projects.map(async (project) => {
|
|
332
|
-
await buildProject(project, options);
|
|
333
|
-
logInfo(`updated ${formatPath(project.distDir, cwd)} from ${formatPath(project.srcDir, cwd)} using ${formatPath(project.tsconfigPath, cwd)}`);
|
|
334
|
-
}));
|
|
335
|
-
return projects;
|
|
336
|
-
}
|
|
337
|
-
function createDebouncedProjectRunner(project, cwd, options) {
|
|
338
|
-
let closed = false;
|
|
339
|
-
let activeBuild;
|
|
340
|
-
let pendingReason;
|
|
341
|
-
let pendingFullRebuild = false;
|
|
342
|
-
let pendingSourcePaths = new Set();
|
|
343
|
-
let timer;
|
|
344
|
-
const excludedAliases = normalizeExcludedAliases(options.excludeAliases);
|
|
345
|
-
const run = async () => {
|
|
346
|
-
if (closed) {
|
|
347
|
-
return;
|
|
348
|
-
}
|
|
349
|
-
if (activeBuild) {
|
|
350
|
-
return;
|
|
351
|
-
}
|
|
352
|
-
const reason = pendingReason ?? 'change';
|
|
353
|
-
const fullRebuild = pendingFullRebuild;
|
|
354
|
-
const sourcePaths = fullRebuild ? [] : [...pendingSourcePaths].sort((left, right) => left.localeCompare(right));
|
|
355
|
-
pendingReason = undefined;
|
|
356
|
-
pendingFullRebuild = false;
|
|
357
|
-
pendingSourcePaths = new Set();
|
|
358
|
-
activeBuild = (async () => {
|
|
359
|
-
if (fullRebuild || sourcePaths.length === 0) {
|
|
360
|
-
logInfo(`rebuilding ${formatPath(project.tsconfigPath, cwd)} after ${reason}`);
|
|
361
|
-
await buildProject(project, {
|
|
362
|
-
...options,
|
|
363
|
-
excludeAliases: excludedAliases
|
|
364
|
-
});
|
|
365
|
-
logInfo(`watch updated ${formatPath(project.distDir, cwd)}`);
|
|
366
|
-
return;
|
|
367
|
-
}
|
|
368
|
-
const resolvedSourcePaths = new Set();
|
|
369
|
-
for (const sourcePath of sourcePaths) {
|
|
370
|
-
const resolvedSourcePath = await resolveWatchedSourcePath(project, sourcePath);
|
|
371
|
-
if (resolvedSourcePath) {
|
|
372
|
-
resolvedSourcePaths.add(resolvedSourcePath);
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
if (resolvedSourcePaths.size === 0) {
|
|
376
|
-
logInfo(`ignoring temporary watch path(s) in ${formatPath(project.tsconfigPath, cwd)} after ${reason}`);
|
|
377
|
-
return;
|
|
378
|
-
}
|
|
379
|
-
logInfo(`updating ${resolvedSourcePaths.size} changed path(s) in ${formatPath(project.tsconfigPath, cwd)} after ${reason}`);
|
|
380
|
-
for (const sourcePath of [...resolvedSourcePaths].sort((left, right) => left.localeCompare(right))) {
|
|
381
|
-
const result = await syncProjectSourcePath(project, sourcePath, excludedAliases);
|
|
382
|
-
if (result === 'rebuilt') {
|
|
383
|
-
logInfo(`watch updated ${formatPath(project.distDir, cwd)}`);
|
|
384
|
-
return;
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
logInfo(`watch updated ${formatPath(project.distDir, cwd)}`);
|
|
388
|
-
})();
|
|
389
|
-
try {
|
|
390
|
-
await activeBuild;
|
|
391
|
-
}
|
|
392
|
-
finally {
|
|
393
|
-
activeBuild = undefined;
|
|
394
|
-
if (pendingReason) {
|
|
395
|
-
await run();
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
};
|
|
399
|
-
return {
|
|
400
|
-
close() {
|
|
401
|
-
closed = true;
|
|
402
|
-
if (timer) {
|
|
403
|
-
clearTimeout(timer);
|
|
404
|
-
timer = undefined;
|
|
405
|
-
}
|
|
406
|
-
},
|
|
407
|
-
schedule(reason, sourceRelativePath) {
|
|
408
|
-
if (closed) {
|
|
409
|
-
return;
|
|
410
|
-
}
|
|
411
|
-
pendingReason = reason;
|
|
412
|
-
if (sourceRelativePath) {
|
|
413
|
-
if (!pendingFullRebuild) {
|
|
414
|
-
pendingSourcePaths.add(sourceRelativePath);
|
|
415
|
-
}
|
|
416
|
-
}
|
|
417
|
-
else {
|
|
418
|
-
pendingFullRebuild = true;
|
|
419
|
-
pendingSourcePaths.clear();
|
|
420
|
-
}
|
|
421
|
-
if (timer) {
|
|
422
|
-
clearTimeout(timer);
|
|
423
|
-
}
|
|
424
|
-
timer = setTimeout(() => {
|
|
425
|
-
timer = undefined;
|
|
426
|
-
void run().catch((error) => {
|
|
427
|
-
logError(`watch rebuild failed for ${formatPath(project.tsconfigPath, cwd)}: ${error.message}`);
|
|
428
|
-
});
|
|
429
|
-
}, 100);
|
|
430
|
-
}
|
|
431
|
-
};
|
|
432
|
-
}
|
|
433
|
-
function watchProject(project, cwd, options) {
|
|
434
|
-
const runner = createDebouncedProjectRunner(project, cwd, options);
|
|
435
|
-
const sourceWatcher = watch(project.srcDir, { recursive: true }, (_eventType, fileName) => {
|
|
436
|
-
runner.schedule('src change', fileName?.toString());
|
|
437
|
-
});
|
|
438
|
-
const configWatcher = watch(project.tsconfigPath, () => {
|
|
439
|
-
runner.schedule('tsconfig change');
|
|
440
|
-
});
|
|
441
|
-
return [
|
|
442
|
-
sourceWatcher,
|
|
443
|
-
configWatcher,
|
|
444
|
-
{
|
|
445
|
-
close() {
|
|
446
|
-
runner.close();
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
];
|
|
450
|
-
}
|
|
451
|
-
export async function watchProjects(options = {}) {
|
|
452
|
-
const cwd = options.cwd ?? process.cwd();
|
|
453
|
-
const projects = await buildProjects(options);
|
|
454
|
-
const watchers = projects.flatMap((project) => watchProject(project, cwd, options));
|
|
455
|
-
logInfo(`watching ${projects.length} project(s)`);
|
|
456
|
-
return {
|
|
457
|
-
close() {
|
|
458
|
-
for (const watcher of watchers) {
|
|
459
|
-
watcher.close();
|
|
460
|
-
}
|
|
461
|
-
},
|
|
462
|
-
projects
|
|
463
|
-
};
|
|
464
|
-
}
|
|
465
|
-
export function parseCliArgs(args) {
|
|
466
|
-
const excludeAliases = [];
|
|
467
|
-
const inputs = [];
|
|
468
|
-
let watchMode = false;
|
|
469
|
-
for (let index = 0; index < args.length; index += 1) {
|
|
470
|
-
const arg = args[index];
|
|
471
|
-
if (arg === '-w' || arg === '--watch') {
|
|
472
|
-
watchMode = true;
|
|
473
|
-
continue;
|
|
474
|
-
}
|
|
475
|
-
if (arg === '--exclude-alias') {
|
|
476
|
-
const value = args[index + 1];
|
|
477
|
-
if (!value || value.startsWith('-')) {
|
|
478
|
-
throw new Error('Missing value for --exclude-alias');
|
|
479
|
-
}
|
|
480
|
-
excludeAliases.push(...value
|
|
481
|
-
.split(',')
|
|
482
|
-
.map((item) => item.trim())
|
|
483
|
-
.filter(Boolean));
|
|
484
|
-
index += 1;
|
|
485
|
-
continue;
|
|
486
|
-
}
|
|
487
|
-
if (arg.startsWith('--exclude-alias=')) {
|
|
488
|
-
excludeAliases.push(...arg
|
|
489
|
-
.slice('--exclude-alias='.length)
|
|
490
|
-
.split(',')
|
|
491
|
-
.map((item) => item.trim())
|
|
492
|
-
.filter(Boolean));
|
|
493
|
-
continue;
|
|
494
|
-
}
|
|
495
|
-
if (arg === '-h' || arg === '--help') {
|
|
496
|
-
printUsage();
|
|
497
|
-
process.exit(0);
|
|
498
|
-
}
|
|
499
|
-
if (arg.startsWith('-')) {
|
|
500
|
-
throw new Error(`Unknown option "${arg}"`);
|
|
501
|
-
}
|
|
502
|
-
inputs.push(arg);
|
|
503
|
-
}
|
|
504
|
-
return {
|
|
505
|
-
excludeAliases,
|
|
506
|
-
inputs,
|
|
507
|
-
watchMode
|
|
508
|
-
};
|
|
509
|
-
}
|
|
510
|
-
function printUsage() {
|
|
511
|
-
console.log([
|
|
512
|
-
'Usage: resolve-paths [--watch] [tsconfig.json path or glob ...]',
|
|
513
|
-
'',
|
|
514
|
-
'Examples:',
|
|
515
|
-
' resolve-paths',
|
|
516
|
-
' resolve-paths tsconfig.json',
|
|
517
|
-
" resolve-paths --exclude-alias '$shared,$generated' tsconfig.json",
|
|
518
|
-
" resolve-paths 'packages/*/tsconfig.json'",
|
|
519
|
-
" resolve-paths --watch 'packages/*/tsconfig.json'"
|
|
520
|
-
].join('\n'));
|
|
521
|
-
}
|
|
522
|
-
function normalizeExecutablePath(targetPath) {
|
|
523
|
-
try {
|
|
524
|
-
return realpathSync.native(targetPath);
|
|
525
|
-
}
|
|
526
|
-
catch {
|
|
527
|
-
return resolve(targetPath);
|
|
528
|
-
}
|
|
529
|
-
}
|
|
530
|
-
export function isDirectExecution(entryPath = process.argv[1], moduleUrl = import.meta.url) {
|
|
531
|
-
if (!entryPath) {
|
|
532
|
-
return false;
|
|
533
|
-
}
|
|
534
|
-
return normalizeExecutablePath(entryPath) === normalizeExecutablePath(fileURLToPath(moduleUrl));
|
|
535
|
-
}
|
|
536
|
-
export async function main(args = process.argv.slice(2)) {
|
|
537
|
-
const { excludeAliases, inputs, watchMode } = parseCliArgs(args);
|
|
538
|
-
if (watchMode) {
|
|
539
|
-
await watchProjects({ excludeAliases, inputs });
|
|
540
|
-
return;
|
|
541
|
-
}
|
|
542
|
-
await buildProjects({ excludeAliases, inputs });
|
|
543
|
-
}
|
|
544
|
-
if (isDirectExecution()) {
|
|
545
|
-
void main().catch((error) => {
|
|
546
|
-
logError(error.message);
|
|
547
|
-
process.exit(1);
|
|
548
|
-
});
|
|
549
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"log.d.ts","sourceRoot":"","sources":["../../../src/lib/scripts/resolve-paths/log.ts"],"names":[],"mappings":"AAIA,wBAAgB,IAAI,WAanB;AAED,wBAAgB,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAE7C;AAED,wBAAgB,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAE9C"}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { styleText } from 'util';
|
|
2
|
-
const LABEL = '[resolve-paths]';
|
|
3
|
-
export function time() {
|
|
4
|
-
const now = new Date();
|
|
5
|
-
let hours = now.getHours();
|
|
6
|
-
const minutes = now.getMinutes();
|
|
7
|
-
const seconds = now.getSeconds();
|
|
8
|
-
const ampm = hours >= 12 ? 'PM' : 'AM';
|
|
9
|
-
hours = hours % 12 || 12;
|
|
10
|
-
const pad = (n) => n.toString().padStart(2, '0');
|
|
11
|
-
return styleText('grey', `[${pad(hours)}:${pad(minutes)}:${pad(seconds)} ${ampm}]`);
|
|
12
|
-
}
|
|
13
|
-
export function logInfo(message) {
|
|
14
|
-
console.log(`${LABEL} ${time()} ${message}`);
|
|
15
|
-
}
|
|
16
|
-
export function logError(message) {
|
|
17
|
-
console.error(`${LABEL} ${time()} ${message}`);
|
|
18
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"resolve-paths.unit.test.d.ts","sourceRoot":"","sources":["../../../src/lib/scripts/resolve-paths/resolve-paths.unit.test.ts"],"names":[],"mappings":""}
|