Skip to content

Commit c5cd0cc

Browse files
committed
refactor: Refactor isPrePostScript()
1 parent 3af34a5 commit c5cd0cc

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

extensions/npm/src/tasks.ts

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -103,22 +103,18 @@ function isTestTask(name: string): boolean {
103103
}
104104
return false;
105105
}
106+
const preScripts: Set<string> = new Set([
107+
'est', /* test typo? */ 'install', 'pack', 'pack', 'publish', 'restart',
108+
'shrinkwrap', 'stop', 'uninstall', 'version'
109+
]);
106110

107-
function isPrePostScript(name: string): boolean {
108-
const prePostScripts: Set<string> = new Set([
109-
'preuninstall', 'postuninstall', 'prepack', 'postpack', 'preinstall', 'postinstall',
110-
'prepack', 'postpack', 'prepublish', 'postpublish', 'preversion', 'postversion',
111-
'prestop', 'poststop', 'prerestart', 'postrestart', 'preshrinkwrap', 'postshrinkwrap',
112-
'pretest', 'postest', 'prepublishOnly'
113-
]);
114-
115-
const prepost = ['pre' + name, 'post' + name];
116-
for (const knownScript of prePostScripts) {
117-
if (knownScript === prepost[0] || knownScript === prepost[1]) {
118-
return true;
119-
}
120-
}
121-
return false;
111+
const postScripts: Set<string> = new Set([
112+
'install', 'pack', 'pack', 'publish', 'publishOnly', 'restart', 'shrinkwrap',
113+
'stop', 'test', 'uninstall', 'version'
114+
]);
115+
116+
function canHavePrePostScript(name: string): boolean {
117+
return preScripts.has(name) || postScripts.has(name);
122118
}
123119

124120
export function isWorkspaceFolder(value: any): value is WorkspaceFolder {
@@ -350,7 +346,7 @@ export async function createScriptRunnerTask(context: ExtensionContext, script:
350346
task.group = TaskGroup.Build;
351347
} else if (isTestTask(lowerCaseTaskName)) {
352348
task.group = TaskGroup.Test;
353-
} else if (isPrePostScript(lowerCaseTaskName)) {
349+
} else if (canHavePrePostScript(lowerCaseTaskName)) {
354350
task.group = TaskGroup.Clean; // hack: use Clean group to tag pre/post scripts
355351
} else if (scriptValue && isDebugScript(scriptValue)) {
356352
// todo@connor4312: all scripts are now debuggable, what is a 'debug script'?

0 commit comments

Comments
 (0)