We are no longer including our dependencies in the VSIX package, so we can tell VSCE that we don't want it to look at dependencies using `--no-dependencies`. If we do this, VSCE doesn't require the `node_modules` directory anymore and we can skip that step, which will make building significantly faster. I've confirmed that there are no changes between the two options by building the extension both without and with the change. This is the diff of the two outputs (using `diff -r`): ```diff diff --color -r vscode-codeql-1.8.0-dev.2023.3.8.15.10.13/extension/package.json vscode-codeql-old/extension/package.json 7c7 < "version": "1.8.0-dev.2023.3.8.15.10.13", --- > "version": "1.8.0-dev.2023.3.8.15.6.51", diff --color -r vscode-codeql-1.8.0-dev.2023.3.8.15.10.13/extension.vsixmanifest vscode-codeql-old/extension.vsixmanifest 4c4 < <Identity Language="en-US" Id="vscode-codeql" Version="1.8.0-dev.2023.3.8.15.10.13" Publisher="GitHub" /> --- > <Identity Language="en-US" Id="vscode-codeql" Version="1.8.0-dev.2023.3.8.15.6.51" Publisher="GitHub" /> ``` The only difference is the version number, which is expected.
106 lines
2.5 KiB
TypeScript
106 lines
2.5 KiB
TypeScript
import {
|
|
copy,
|
|
readFile,
|
|
mkdirs,
|
|
readdir,
|
|
unlinkSync,
|
|
remove,
|
|
writeFile,
|
|
} from "fs-extra";
|
|
import { resolve, join } from "path";
|
|
import { isDevBuild } from "./dev";
|
|
|
|
export interface DeployedPackage {
|
|
distPath: string;
|
|
name: string;
|
|
version: string;
|
|
}
|
|
|
|
const packageFiles = [
|
|
".vscodeignore",
|
|
"CHANGELOG.md",
|
|
"README.md",
|
|
"language-configuration.json",
|
|
"snippets.json",
|
|
"media",
|
|
"out",
|
|
"databases-schema.json",
|
|
];
|
|
|
|
async function copyDirectory(
|
|
sourcePath: string,
|
|
destPath: string,
|
|
): Promise<void> {
|
|
console.log(`copying ${sourcePath} to ${destPath}`);
|
|
await copy(sourcePath, destPath);
|
|
}
|
|
|
|
async function copyPackage(
|
|
sourcePath: string,
|
|
destPath: string,
|
|
): Promise<void> {
|
|
await Promise.all(
|
|
packageFiles.map((file) =>
|
|
copyDirectory(resolve(sourcePath, file), resolve(destPath, file)),
|
|
),
|
|
);
|
|
}
|
|
|
|
export async function deployPackage(
|
|
packageJsonPath: string,
|
|
): Promise<DeployedPackage> {
|
|
try {
|
|
const packageJson: any = JSON.parse(
|
|
await readFile(packageJsonPath, "utf8"),
|
|
);
|
|
|
|
const distDir = join(__dirname, "../../../dist");
|
|
await mkdirs(distDir);
|
|
|
|
if (isDevBuild) {
|
|
// NOTE: rootPackage.name had better not have any regex metacharacters
|
|
const oldDevBuildPattern = new RegExp(
|
|
`^${packageJson.name}[^/]+-dev[0-9.]+\\.vsix$`,
|
|
);
|
|
// Dev package filenames are of the form
|
|
// vscode-codeql-0.0.1-dev.2019.9.27.19.55.20.vsix
|
|
(await readdir(distDir))
|
|
.filter((name) => name.match(oldDevBuildPattern))
|
|
.map((build) => {
|
|
console.log(`Deleting old dev build ${build}...`);
|
|
unlinkSync(join(distDir, build));
|
|
});
|
|
const now = new Date();
|
|
packageJson.version =
|
|
`${packageJson.version}-dev.${now.getUTCFullYear()}.${
|
|
now.getUTCMonth() + 1
|
|
}.${now.getUTCDate()}` +
|
|
`.${now.getUTCHours()}.${now.getUTCMinutes()}.${now.getUTCSeconds()}`;
|
|
}
|
|
|
|
const distPath = join(distDir, packageJson.name);
|
|
await remove(distPath);
|
|
await mkdirs(distPath);
|
|
|
|
await writeFile(
|
|
join(distPath, "package.json"),
|
|
JSON.stringify(packageJson, null, 2),
|
|
);
|
|
|
|
const sourcePath = join(__dirname, "..");
|
|
console.log(
|
|
`Copying package '${packageJson.name}' and its dependencies to '${distPath}'...`,
|
|
);
|
|
await copyPackage(sourcePath, distPath);
|
|
|
|
return {
|
|
distPath,
|
|
name: packageJson.name,
|
|
version: packageJson.version,
|
|
};
|
|
} catch (e) {
|
|
console.error(e);
|
|
throw e;
|
|
}
|
|
}
|