From a0e1a71c408c7cf7583a6eae217b6d815deeea7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Tron=C3=AD=C4=8Dek?= Date: Mon, 28 Feb 2022 22:56:02 +0000 Subject: [PATCH 1/6] Add a `custom` property --- extensions-schema.json | 4 ++ extensions.json | 2 +- publish-extension.js | 91 +++++++++++++++++++++++------------------- types.d.ts | 1 + 4 files changed, 57 insertions(+), 41 deletions(-) diff --git a/extensions-schema.json b/extensions-schema.json index e2897f3a3..4c0a6c3b6 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": "string", + "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 39c9ab96b..1acdbe06b 100644 --- a/extensions.json +++ b/extensions.json @@ -881,7 +881,7 @@ "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 && npx vsce package --yarn --out extension.vsix" }, "ms-vscode.vscode-smoketest-check": { "repository": "https://github.com/microsoft/vscode-smoketest-check" diff --git a/publish-extension.js b/publish-extension.js index d0d0f390a..d73b78638 100644 --- a/publish-extension.js +++ b/publish-extension.js @@ -39,52 +39,61 @@ 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 { + await exec(extension.custom, { 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 +102,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 +112,7 @@ const { createVSIX } = require('vsce'); return; } } + // TODO(ak) check license is open-source if (!xmlManifest?.PackageManifest?.Metadata[0]?.License?.[0] && !(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..baa67a5bc 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 } From 4bc25280de016dd2eb3a65e0acfedc4c1f14045d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Tron=C3=AD=C4=8Dek?= Date: Tue, 1 Mar 2022 20:12:00 +0000 Subject: [PATCH 2/6] Fix `formulahendry.auto-rename-tag` --- extensions.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/extensions.json b/extensions.json index 1acdbe06b..f09f35c2d 100644 --- a/extensions.json +++ b/extensions.json @@ -372,7 +372,8 @@ }, "formulahendry.auto-rename-tag": { "repository": "https://github.com/formulahendry/vscode-auto-rename-tag", - "location": "packages/extension" + "location": "packages/extension", + "custom": "npm i -g vsce && 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" From 6ff636167925259d3b30bb118baac1093a771313 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Tron=C3=AD=C4=8Dek?= Date: Thu, 10 Mar 2022 15:58:50 +0000 Subject: [PATCH 3/6] Make the property an array --- extensions-schema.json | 2 +- extensions.json | 16 +++++++++++++--- publish-extension.js | 4 +++- types.d.ts | 2 +- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/extensions-schema.json b/extensions-schema.json index 4c0a6c3b6..679e51428 100644 --- a/extensions-schema.json +++ b/extensions-schema.json @@ -25,7 +25,7 @@ "description": "Relative path of the extension vsix file inside the git repo (i.e. when it is built by prepublish commands" }, "custom": { - "type": "string", + "type": "array", "description": "Build using a custom script. Must output an `extension.vsix` file in the `location` directory." }, "timeout": { diff --git a/extensions.json b/extensions.json index 7c58e5880..e9fc28a5b 100644 --- a/extensions.json +++ b/extensions.json @@ -370,7 +370,12 @@ "formulahendry.auto-rename-tag": { "repository": "https://github.com/formulahendry/vscode-auto-rename-tag", "location": "packages/extension", - "custom": "npm i -g vsce && npm i && npm run package && mv dist/auto-rename-tag-*.vsix packages/extension/extension.vsix" + "custom": [ + "npm i -g vsce", + "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" @@ -874,7 +879,12 @@ "ms-vscode.vscode-js-profile-table": { "repository": "https://github.com/microsoft/vscode-js-profile-visualizer", "location": "packages/vscode-js-profile-table", - "custom": "npm install && npm run compile && cd packages/vscode-js-profile-table && npx vsce package --yarn --out extension.vsix" + "custom": [ + "npm install", + "npm run compile", + "cd packages/vscode-js-profile-table", + "npx vsce package --yarn --out extension.vsix" + ] }, "ms-vscode.vscode-smoketest-check": { "repository": "https://github.com/microsoft/vscode-smoketest-check" @@ -1293,4 +1303,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 a528a9224..fc779c860 100644 --- a/publish-extension.js +++ b/publish-extension.js @@ -41,7 +41,9 @@ const { createVSIX } = require('vsce'); await exec(`git checkout ${context.ref}`, { cwd: context.repo }); if (extension.custom) { try { - await exec(extension.custom, { cwd: context.repo }); + 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; diff --git a/types.d.ts b/types.d.ts index baa67a5bc..b9659434b 100644 --- a/types.d.ts +++ b/types.d.ts @@ -58,7 +58,7 @@ export interface Extension { location?: string prepublish?: string extensionFile?: string - custom?: string + custom?: string[] timeout?: number } From 21d303c223c9e2a8d73b92d86ab4739f36c6f04d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Tron=C3=AD=C4=8Dek?= Date: Thu, 10 Mar 2022 19:42:06 +0100 Subject: [PATCH 4/6] Update extensions.json Co-authored-by: Manuel Thalmann --- extensions.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/extensions.json b/extensions.json index e9fc28a5b..44572821f 100644 --- a/extensions.json +++ b/extensions.json @@ -882,8 +882,7 @@ "custom": [ "npm install", "npm run compile", - "cd packages/vscode-js-profile-table", - "npx vsce package --yarn --out extension.vsix" + "cd packages/vscode-js-profile-table && npx vsce package --yarn --out extension.vsix" ] }, "ms-vscode.vscode-smoketest-check": { From c1a9579f5ee8e432321e812b67cc99436425f1b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Tron=C3=AD=C4=8Dek?= Date: Thu, 10 Mar 2022 20:00:23 +0000 Subject: [PATCH 5/6] Add `custom` notice to the README --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 456e0b177..0df19f512 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,9 @@ The [publishing process](https://github.com/open-vsx/publish-extensions/blob/d2d 1. [`git clone "repository"`](https://github.com/open-vsx/publish-extensions/blob/d2df425a84093023f4ee164592f2491c32166297/publish-extensions.js#L61) 2. _([`git checkout "checkout"`](https://github.com/open-vsx/publish-extensions/blob/d2df425a84093023f4ee164592f2491c32166297/publish-extensions.js#L63) if a `"checkout"` value is specified)_ + +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) + 3. [`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) 4. _([`"prepublish"`](https://github.com/open-vsx/publish-extensions/blob/d2df425a84093023f4ee164592f2491c32166297/publish-extensions.js#L70))_ 5. _([`ovsx create-namespace "publisher"`](https://github.com/open-vsx/publish-extensions/blob/d2df425a84093023f4ee164592f2491c32166297/publish-extensions.js#L75) if it doesn't already exist)_ From 8a01b8a37792ac8440360f360abdc3e1584a0b90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Tron=C3=AD=C4=8Dek?= Date: Tue, 15 Mar 2022 17:39:27 +0000 Subject: [PATCH 6/6] vsce now preinstalled --- extensions.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/extensions.json b/extensions.json index b76dcc928..49af219a1 100644 --- a/extensions.json +++ b/extensions.json @@ -374,7 +374,6 @@ "repository": "https://github.com/formulahendry/vscode-auto-rename-tag", "location": "packages/extension", "custom": [ - "npm i -g vsce", "npm i", "npm run package", "mv dist/auto-rename-tag-*.vsix packages/extension/extension.vsix" @@ -885,7 +884,7 @@ "custom": [ "npm install", "npm run compile", - "cd packages/vscode-js-profile-table && npx vsce package --yarn --out extension.vsix" + "cd packages/vscode-js-profile-table && vsce package --yarn --out extension.vsix" ] }, "ms-vscode.vscode-smoketest-check": {