scripting-cli 1.4.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/controller.d.ts +2 -0
- package/dist/controller.js +2 -0
- package/dist/util.js +39 -13
- package/package.json +1 -1
package/dist/controller.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ export declare class Controller {
|
|
|
15
15
|
handleSyncScriptFromClient: (data: {
|
|
16
16
|
[globalDtsFileName]: string;
|
|
17
17
|
[scriptingDtsFileName]: string;
|
|
18
|
+
extraDtsFiles?: Record<string, string>;
|
|
18
19
|
scriptName: string;
|
|
19
20
|
scriptFiles: Record<string, string>;
|
|
20
21
|
}, ack: (result: {
|
|
@@ -24,6 +25,7 @@ export declare class Controller {
|
|
|
24
25
|
handleSyncScriptFromServer: (data: {
|
|
25
26
|
"global.d.ts": string;
|
|
26
27
|
"scripting.d.ts": string;
|
|
28
|
+
extraDtsFiles?: Record<string, string>;
|
|
27
29
|
scriptName: string;
|
|
28
30
|
}, ack: (result: {
|
|
29
31
|
error?: string;
|
package/dist/controller.js
CHANGED
|
@@ -116,6 +116,7 @@ class Controller {
|
|
|
116
116
|
await (0, util_1.writeDtsFiles)({
|
|
117
117
|
[const_1.globalDtsFileName]: data[const_1.globalDtsFileName],
|
|
118
118
|
[const_1.scriptingDtsFileName]: data[const_1.scriptingDtsFileName],
|
|
119
|
+
...(data.extraDtsFiles ?? {}),
|
|
119
120
|
});
|
|
120
121
|
this.scriptName = data.scriptName;
|
|
121
122
|
const scriptDir = (0, util_1.getScriptPath)(data.scriptName);
|
|
@@ -166,6 +167,7 @@ class Controller {
|
|
|
166
167
|
await (0, util_1.writeDtsFiles)({
|
|
167
168
|
[const_1.globalDtsFileName]: data[const_1.globalDtsFileName],
|
|
168
169
|
[const_1.scriptingDtsFileName]: data[const_1.scriptingDtsFileName],
|
|
170
|
+
...(data.extraDtsFiles ?? {}),
|
|
169
171
|
});
|
|
170
172
|
const scriptDir = (0, util_1.getScriptPath)(data.scriptName);
|
|
171
173
|
if (!fs_1.default.existsSync(scriptDir)) {
|
package/dist/util.js
CHANGED
|
@@ -123,8 +123,11 @@ function createTsConfig() {
|
|
|
123
123
|
}
|
|
124
124
|
},
|
|
125
125
|
"include": [
|
|
126
|
-
"./dts
|
|
126
|
+
"./dts/*.d.ts",
|
|
127
127
|
"scripts"
|
|
128
|
+
],
|
|
129
|
+
"exclude": [
|
|
130
|
+
"./dts/${const_1.scriptingDtsFileName}"
|
|
128
131
|
]
|
|
129
132
|
}`;
|
|
130
133
|
const filePath = getPath('tsconfig.json');
|
|
@@ -132,20 +135,35 @@ function createTsConfig() {
|
|
|
132
135
|
if (!fs_1.default.existsSync(filePath)) {
|
|
133
136
|
fs_1.default.writeFileSync(filePath, tsconfigContent);
|
|
134
137
|
console.log(chalk_1.default.green('tsconfig.json created.'));
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
// Migrate an existing tsconfig to the current include/exclude shape:
|
|
141
|
+
// - all ambient dts are picked up via the "./dts/*.d.ts" glob (so newly synced
|
|
142
|
+
// node.d.ts / web-fetch.d.ts / safari-ext.d.ts are covered automatically),
|
|
143
|
+
// - scripting.d.ts is excluded from the root program (it stays importable via
|
|
144
|
+
// the "scripting" paths mapping). Existing custom entries are preserved.
|
|
145
|
+
const tsconfig = JSON.parse(fs_1.default.readFileSync(filePath, 'utf-8'));
|
|
146
|
+
const include = Array.isArray(tsconfig.include) ? [...tsconfig.include] : [];
|
|
147
|
+
const exclude = Array.isArray(tsconfig.exclude) ? [...tsconfig.exclude] : [];
|
|
148
|
+
// Drop the stale explicit global entry now covered by the glob.
|
|
149
|
+
let nextInclude = include.filter((x) => x !== `./dts/${const_1.globalDtsFileName}`);
|
|
150
|
+
if (!nextInclude.includes('./dts/*.d.ts'))
|
|
151
|
+
nextInclude.unshift('./dts/*.d.ts');
|
|
152
|
+
if (!nextInclude.includes('scripts'))
|
|
153
|
+
nextInclude.push('scripts');
|
|
154
|
+
const nextExclude = exclude.includes(`./dts/${const_1.scriptingDtsFileName}`)
|
|
155
|
+
? exclude
|
|
156
|
+
: [...exclude, `./dts/${const_1.scriptingDtsFileName}`];
|
|
157
|
+
const includeChanged = JSON.stringify(nextInclude) !== JSON.stringify(include);
|
|
158
|
+
const excludeChanged = JSON.stringify(nextExclude) !== JSON.stringify(exclude);
|
|
159
|
+
if (includeChanged || excludeChanged) {
|
|
160
|
+
tsconfig.include = nextInclude;
|
|
161
|
+
tsconfig.exclude = nextExclude;
|
|
162
|
+
fs_1.default.writeFileSync(filePath, JSON.stringify(tsconfig, null, 2));
|
|
163
|
+
console.log(chalk_1.default.yellow('tsconfig.json updated to sync all ambient type declarations.'));
|
|
135
164
|
}
|
|
136
165
|
else {
|
|
137
|
-
|
|
138
|
-
if (tsconfig.include && !tsconfig.include.includes('scripts')) {
|
|
139
|
-
tsconfig.include = [
|
|
140
|
-
`./dts/${const_1.globalDtsFileName}`,
|
|
141
|
-
"scripts"
|
|
142
|
-
];
|
|
143
|
-
fs_1.default.writeFileSync(filePath, JSON.stringify(tsconfig, null, 2));
|
|
144
|
-
console.log(chalk_1.default.yellow('tsconfig.json updated to include scripts directory.'));
|
|
145
|
-
}
|
|
146
|
-
else {
|
|
147
|
-
console.log(chalk_1.default.gray('tsconfig.json already exists.'));
|
|
148
|
-
}
|
|
166
|
+
console.log(chalk_1.default.gray('tsconfig.json already exists.'));
|
|
149
167
|
}
|
|
150
168
|
}
|
|
151
169
|
function ensureScriptsDirectory() {
|
|
@@ -166,6 +184,14 @@ function ensureDirectoryExistence(filePath) {
|
|
|
166
184
|
}
|
|
167
185
|
async function writeDtsFiles(files) {
|
|
168
186
|
await Promise.all(Object.entries(files).map(async ([filename, content]) => {
|
|
187
|
+
// These names arrive over the wire; only allow a plain `.d.ts` basename so
|
|
188
|
+
// a crafted name can't escape the dts/ directory.
|
|
189
|
+
if (typeof content !== 'string' ||
|
|
190
|
+
filename !== path_1.default.basename(filename) ||
|
|
191
|
+
!filename.endsWith('.d.ts')) {
|
|
192
|
+
console.log(chalk_1.default.red(`Skipped writing dts file with unexpected name: ${filename}`));
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
169
195
|
const filePath = getPath(`dts/${filename}`);
|
|
170
196
|
ensureDirectoryExistence(filePath);
|
|
171
197
|
await fs_1.default
|