Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ Every night at [03:03 UTC](https://github.com/open-vsx/publish-extensions/blob/e
The [publishing process](https://github.com/open-vsx/publish-extensions/blob/d2df425a84093023f4ee164592f2491c32166297/publish-extensions.js#L58-L87) can be summarized like this:

1. [`git clone "repository"`](https://github.com/open-vsx/publish-extensions/blob/d2df425a84093023f4ee164592f2491c32166297/publish-extensions.js#L61)

If a `custom` property is provided, then every command from the array is executed, otherwise, the following 2 steps are executed: (the rest is always the same)

2. [`npm install`](https://github.com/open-vsx/publish-extensions/blob/d2df425a84093023f4ee164592f2491c32166297/publish-extensions.js#L68) (or `yarn install` if a `yarn.lock` file is detected in the repository)
3. _([`"prepublish"`](https://github.com/open-vsx/publish-extensions/blob/d2df425a84093023f4ee164592f2491c32166297/publish-extensions.js#L70))_
4. _([`ovsx create-namespace "publisher"`](https://github.com/open-vsx/publish-extensions/blob/d2df425a84093023f4ee164592f2491c32166297/publish-extensions.js#L75) if it doesn't already exist)_
Expand Down
4 changes: 4 additions & 0 deletions extensions-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
"type": "string",
"description": "Relative path of the extension vsix file inside the git repo (i.e. when it is built by prepublish commands"
},
"custom": {
"type": "array",
"description": "Build using a custom script. Must output an `extension.vsix` file in the `location` directory."
},
"timeout": {
"type": "number",
"description": "Timeout to build the extension vsix from sources."
Expand Down
15 changes: 12 additions & 3 deletions extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,12 @@
},
"formulahendry.auto-rename-tag": {
"repository": "https://github.com/formulahendry/vscode-auto-rename-tag",
"location": "packages/extension"
"location": "packages/extension",
"custom": [
"npm i",
"npm run package",
"mv dist/auto-rename-tag-*.vsix packages/extension/extension.vsix"
]
},
"formulahendry.code-runner": {
"repository": "https://github.com/formulahendry/vscode-code-runner"
Expand Down Expand Up @@ -878,7 +883,11 @@
"ms-vscode.vscode-js-profile-table": {
"repository": "https://github.com/microsoft/vscode-js-profile-visualizer",
"location": "packages/vscode-js-profile-table",
"prepublish": "npm run compile"
"custom": [
"npm install",
"npm run compile",
"cd packages/vscode-js-profile-table && vsce package --yarn --out extension.vsix"
]
},
"ms-vscode.vscode-smoketest-check": {
"repository": "https://github.com/microsoft/vscode-smoketest-check"
Expand Down Expand Up @@ -1300,4 +1309,4 @@
"zxh404.vscode-proto3": {
"repository": "https://github.com/zxh0/vscode-proto3"
}
}
}
93 changes: 53 additions & 40 deletions publish-extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,52 +39,63 @@ const { createVSIX } = require('vsce');
} else if (context.repo && context.ref) {
console.log(`${id}: preparing from ${context.repo}...`);
await exec(`git checkout ${context.ref}`, { cwd: context.repo });
let yarn = await new Promise(resolve => {
fs.access(path.join(context.repo, 'yarn.lock'), error => resolve(!error));
});
try {
await exec(`${yarn ? 'yarn' : 'npm'} install`, { cwd: packagePath });
} catch (e) {
const pck = JSON.parse(await fs.promises.readFile(path.join(packagePath, 'package.json'), 'utf-8'));
// try to auto migrate from vscode: https://code.visualstudio.com/api/working-with-extensions/testing-extension#migrating-from-vscode
if (pck.scripts?.postinstall === 'node ./node_modules/vscode/bin/install') {
delete pck.scripts['postinstall'];
pck.devDependencies = pck.devDependencies || {};
delete pck.devDependencies['vscode'];
pck.devDependencies['@types/vscode'] = pck.engines['vscode'];
const content = JSON.stringify(pck, undefined, 2).replace(/node \.\/node_modules\/vscode\/bin\/compile/g, 'tsc');
await fs.promises.writeFile(path.join(packagePath, 'package.json'), content, 'utf-8');
await exec(`${yarn ? 'yarn' : 'npm'} install`, { cwd: packagePath });
} else {
if (extension.custom) {
try {
for (const command of extension.custom) {
await exec(command, { cwd: context.repo });
}
options = { extensionFile: path.join(context.repo, extension.location, 'extension.vsix') };
} catch (e) {
throw e;
}
}
if (extension.prepublish) {
await exec(extension.prepublish, { cwd: context.repo })
}
if (extension.extensionFile) {
options = { extensionFile: path.join(context.repo, extension.extensionFile) };
} else {
options = { extensionFile: path.join(context.repo, 'extension.vsix') };
if (yarn) {
options.yarn = true;
}
// answer y to all quetions https://github.com/microsoft/vscode-vsce/blob/7182692b0f257dc10e7fc643269511549ca0c1db/src/util.ts#L12
const vsceTests = process.env['VSCE_TESTS'];
process.env['VSCE_TESTS'] = '1';
let yarn = await new Promise(resolve => {
fs.access(path.join(context.repo, 'yarn.lock'), error => resolve(!error));
});
try {
await createVSIX({
cwd: packagePath,
packagePath: options.extensionFile,
baseContentUrl: options.baseContentUrl,
baseImagesUrl: options.baseImagesUrl,
useYarn: options.yarn
});
} finally {
process.env['VSCE_TESTS'] = vsceTests;
await exec(`${yarn ? 'yarn' : 'npm'} install`, { cwd: packagePath });
} catch (e) {
const pck = JSON.parse(await fs.promises.readFile(path.join(packagePath, 'package.json'), 'utf-8'));
// try to auto migrate from vscode: https://code.visualstudio.com/api/working-with-extensions/testing-extension#migrating-from-vscode
if (pck.scripts?.postinstall === 'node ./node_modules/vscode/bin/install') {
delete pck.scripts['postinstall'];
pck.devDependencies = pck.devDependencies || {};
delete pck.devDependencies['vscode'];
pck.devDependencies['@types/vscode'] = pck.engines['vscode'];
const content = JSON.stringify(pck, undefined, 2).replace(/node \.\/node_modules\/vscode\/bin\/compile/g, 'tsc');
await fs.promises.writeFile(path.join(packagePath, 'package.json'), content, 'utf-8');
await exec(`${yarn ? 'yarn' : 'npm'} install`, { cwd: packagePath });
} else {
throw e;
}
}
if (extension.prepublish) {
await exec(extension.prepublish, { cwd: context.repo })
}
if (extension.extensionFile) {
options = { extensionFile: path.join(context.repo, extension.extensionFile) };
} else {
options = { extensionFile: path.join(context.repo, 'extension.vsix') };
if (yarn) {
options.yarn = true;
}
// answer y to all quetions https://github.com/microsoft/vscode-vsce/blob/7182692b0f257dc10e7fc643269511549ca0c1db/src/util.ts#L12
const vsceTests = process.env['VSCE_TESTS'];
process.env['VSCE_TESTS'] = '1';
try {
await createVSIX({
cwd: packagePath,
packagePath: options.extensionFile,
baseContentUrl: options.baseContentUrl,
baseImagesUrl: options.baseImagesUrl,
useYarn: options.yarn
});
} finally {
process.env['VSCE_TESTS'] = vsceTests;
}
}
console.log(`${id}: prepared from ${context.repo}`);
}
console.log(`${id}: prepared from ${context.repo}`);
}

// Check if the requested version is greater than the one on Open VSX.
Expand All @@ -93,6 +104,7 @@ const { createVSIX } = require('vsce');
if (!context.version) {
throw new Error(`${extension.id}: version is not resolved`);
}

if (context.ovsxVersion) {
if (semver.gt(context.ovsxVersion, context.version)) {
throw new Error(`extensions.json is out-of-date: Open VSX version ${context.ovsxVersion} is already greater than specified version ${context.version}`);
Expand All @@ -102,6 +114,7 @@ const { createVSIX } = require('vsce');
return;
}
}

// TODO(ak) check license is open-source
if (!xmlManifest?.PackageManifest?.Metadata[0]?.License?.[0] && !manifest.license && !(packagePath && await ovsx.isLicenseOk(packagePath, manifest))) {
throw new Error(`${extension.id}: license is missing`);
Expand Down
1 change: 1 addition & 0 deletions types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export interface Extension {
location?: string
prepublish?: string
extensionFile?: string
custom?: string[]
timeout?: number
}

Expand Down