diff --git a/README.md b/README.md index 8f01146b3..2b12c6934 100644 --- a/README.md +++ b/README.md @@ -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)_ diff --git a/extensions-schema.json b/extensions-schema.json index e2897f3a3..679e51428 100644 --- a/extensions-schema.json +++ b/extensions-schema.json @@ -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." diff --git a/extensions.json b/extensions.json index b5833d90b..08d319715 100644 --- a/extensions.json +++ b/extensions.json @@ -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" @@ -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" @@ -1300,4 +1309,4 @@ "zxh404.vscode-proto3": { "repository": "https://github.com/zxh0/vscode-proto3" } -} +} \ No newline at end of file diff --git a/publish-extension.js b/publish-extension.js index 768979479..fc779c860 100644 --- a/publish-extension.js +++ b/publish-extension.js @@ -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. @@ -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}`); @@ -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`); diff --git a/types.d.ts b/types.d.ts index 2819578f4..b9659434b 100644 --- a/types.d.ts +++ b/types.d.ts @@ -58,6 +58,7 @@ export interface Extension { location?: string prepublish?: string extensionFile?: string + custom?: string[] timeout?: number }