From 92c776bc995d617fff6941f2196d591cc4f8e2b3 Mon Sep 17 00:00:00 2001 From: Alex Dima Date: Tue, 21 Aug 2018 12:19:10 +0200 Subject: [PATCH] Move packaging extensions to lib/extensions.ts --- build/dependencies.js | 2 +- build/gulpfile.vscode.js | 42 +++++------------------------- build/lib/extensions.js | 50 +++++++++++++++++++++++++++++++++++ build/lib/extensions.ts | 56 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 114 insertions(+), 36 deletions(-) diff --git a/build/dependencies.js b/build/dependencies.js index a0b1ee01dc5..2adf7e29ca7 100644 --- a/build/dependencies.js +++ b/build/dependencies.js @@ -43,7 +43,7 @@ function asYarnDependency(prefix, tree) { } function getYarnProductionDependencies(cwd) { - const raw = cp.execSync('yarn list --json', { cwd, encoding: 'utf8', env: { ...process.env, NODE_ENV: 'production' }, stdio: [null, null, 'ignore'] }); + const raw = cp.execSync('yarn list --json', { cwd, encoding: 'utf8', env: { ...process.env, NODE_ENV: 'production' }, stdio: [null, null, 'inherit'] }); const match = /^{"type":"tree".*$/m.exec(raw); if (!match || match.length !== 1) { diff --git a/build/gulpfile.vscode.js b/build/gulpfile.vscode.js index d79071e56bc..b06987077c9 100644 --- a/build/gulpfile.vscode.js +++ b/build/gulpfile.vscode.js @@ -29,7 +29,6 @@ const packageJson = require('../package.json'); const product = require('../product.json'); const crypto = require('crypto'); const i18n = require('./lib/i18n'); -const glob = require('glob'); const deps = require('./dependencies'); const getElectronVersion = require('./lib/electron').getElectronVersion; const createAsar = require('./lib/asar').createAsar; @@ -44,15 +43,6 @@ const nodeModules = ['electron', 'original-fs'] .concat(baseModules); // Build -const builtInExtensions = require('./builtInExtensions.json'); - -const excludedExtensions = [ - 'vscode-api-tests', - 'vscode-colorize-tests', - 'ms-vscode.node-debug', - 'ms-vscode.node-debug2', -]; - const vscodeEntryPoints = _.flatten([ buildfile.entrypoint('vs/workbench/workbench.main'), buildfile.base, @@ -227,34 +217,16 @@ function packageTask(platform, arch, opts) { ]); const src = gulp.src(out + '/**', { base: '.' }) - .pipe(rename(function (path) { path.dirname = path.dirname.replace(new RegExp('^' + out), 'out'); })); - - const root = path.resolve(path.join(__dirname, '..')); - const localExtensionDescriptions = glob.sync('extensions/*/package.json') - .map(manifestPath => { - const extensionPath = path.dirname(path.join(root, manifestPath)); - const extensionName = path.basename(extensionPath); - return { name: extensionName, path: extensionPath }; - }) - .filter(({ name }) => excludedExtensions.indexOf(name) === -1) - .filter(({ name }) => builtInExtensions.every(b => b.name !== name)); - - const localExtensions = es.merge(...localExtensionDescriptions.map(extension => { - return ext.fromLocal(extension.path, sourceMappingURLBase) - .pipe(rename(p => p.dirname = `extensions/${extension.name}/${p.dirname}`)); - })); - - const localExtensionDependencies = gulp.src('extensions/node_modules/**', { base: '.' }); - - const marketplaceExtensions = es.merge(...builtInExtensions.map(extension => { - return ext.fromMarketplace(extension.name, extension.version) - .pipe(rename(p => p.dirname = `extensions/${extension.name}/${p.dirname}`)); - })); - - const sources = es.merge(src, localExtensions, localExtensionDependencies, marketplaceExtensions) + .pipe(rename(function (path) { path.dirname = path.dirname.replace(new RegExp('^' + out), 'out'); })) .pipe(util.setExecutableBit(['**/*.sh'])) .pipe(filter(['**', '!**/*.js.map'])); + const root = path.resolve(path.join(__dirname, '..')); + + const sources = es.merge(src, ext.packageExtensionsStream({ + sourceMappingURLBase: sourceMappingURLBase + })); + let version = packageJson.version; // @ts-ignore JSON checking: quality is optional const quality = product.quality; diff --git a/build/lib/extensions.js b/build/lib/extensions.js index a3973e86026..202cded3dcc 100644 --- a/build/lib/extensions.js +++ b/build/lib/extensions.js @@ -28,6 +28,10 @@ var fs = require("fs"); var path = require("path"); var vsce = require("vsce"); var File = require("vinyl"); +var glob = require("glob"); +var gulp = require("gulp"); +var util2 = require("./util"); +var root = path.resolve(path.join(__dirname, '..', '..')); function fromLocal(extensionPath, sourceMappingURLBase) { var result = es.through(); vsce.listFiles({ cwd: extensionPath, packageManager: vsce.PackageManager.Yarn }).then(function (fileNames) { @@ -175,3 +179,49 @@ function fromMarketplace(extensionName, version) { })); } exports.fromMarketplace = fromMarketplace; +var excludedExtensions = [ + 'vscode-api-tests', + 'vscode-colorize-tests', + 'ms-vscode.node-debug', + 'ms-vscode.node-debug2', +]; +var builtInExtensions = require('../builtInExtensions.json'); +function packageExtensionsStream(opts) { + opts = opts || {}; + var localExtensionDescriptions = glob.sync('extensions/*/package.json') + .map(function (manifestPath) { + var extensionPath = path.dirname(path.join(root, manifestPath)); + var extensionName = path.basename(extensionPath); + return { name: extensionName, path: extensionPath }; + }) + .filter(function (_a) { + var name = _a.name; + return excludedExtensions.indexOf(name) === -1; + }) + .filter(function (_a) { + var name = _a.name; + return opts.desiredExtensions ? opts.desiredExtensions.indexOf(name) >= 0 : true; + }) + .filter(function (_a) { + var name = _a.name; + return builtInExtensions.every(function (b) { return b.name !== name; }); + }); + var localExtensions = es.merge.apply(es, localExtensionDescriptions.map(function (extension) { + return fromLocal(extension.path, opts.sourceMappingURLBase) + .pipe(rename(function (p) { return p.dirname = "extensions/" + extension.name + "/" + p.dirname; })); + })); + var localExtensionDependencies = gulp.src('extensions/node_modules/**', { base: '.' }); + var marketplaceExtensions = es.merge.apply(es, builtInExtensions + .filter(function (_a) { + var name = _a.name; + return opts.desiredExtensions ? opts.desiredExtensions.indexOf(name) >= 0 : true; + }) + .map(function (extension) { + return fromMarketplace(extension.name, extension.version) + .pipe(rename(function (p) { return p.dirname = "extensions/" + extension.name + "/" + p.dirname; })); + })); + return es.merge(localExtensions, localExtensionDependencies, marketplaceExtensions) + .pipe(util2.setExecutableBit(['**/*.sh'])) + .pipe(filter(['**', '!**/*.js.map'])); +} +exports.packageExtensionsStream = packageExtensionsStream; diff --git a/build/lib/extensions.ts b/build/lib/extensions.ts index 3922a3218d2..3c74455ccad 100644 --- a/build/lib/extensions.ts +++ b/build/lib/extensions.ts @@ -20,6 +20,11 @@ import * as fs from 'fs'; import * as path from 'path'; import * as vsce from 'vsce'; import * as File from 'vinyl'; +import * as glob from 'glob'; +import * as gulp from 'gulp'; +import * as util2 from './util'; + +const root = path.resolve(path.join(__dirname, '..', '..')); export function fromLocal(extensionPath: string, sourceMappingURLBase?: string): Stream { let result = es.through(); @@ -191,3 +196,54 @@ export function fromMarketplace(extensionName: string, version: string): Stream })); })); } + +interface IPackageExtensionsOptions { + /** + * Set to undefined to package all of them. + */ + desiredExtensions?: string[]; + sourceMappingURLBase?: string; +} + +const excludedExtensions = [ + 'vscode-api-tests', + 'vscode-colorize-tests', + 'ms-vscode.node-debug', + 'ms-vscode.node-debug2', +]; + +const builtInExtensions: { name: string, version: string, repo: string; }[] = require('../builtInExtensions.json'); + +export function packageExtensionsStream(opts?: IPackageExtensionsOptions): NodeJS.ReadWriteStream { + opts = opts || {}; + + const localExtensionDescriptions = (glob.sync('extensions/*/package.json')) + .map(manifestPath => { + const extensionPath = path.dirname(path.join(root, manifestPath)); + const extensionName = path.basename(extensionPath); + return { name: extensionName, path: extensionPath }; + }) + .filter(({ name }) => excludedExtensions.indexOf(name) === -1) + .filter(({ name }) => opts.desiredExtensions ? opts.desiredExtensions.indexOf(name) >= 0 : true) + .filter(({ name }) => builtInExtensions.every(b => b.name !== name)); + + const localExtensions = es.merge(...localExtensionDescriptions.map(extension => { + return fromLocal(extension.path, opts.sourceMappingURLBase) + .pipe(rename(p => p.dirname = `extensions/${extension.name}/${p.dirname}`)); + })); + + const localExtensionDependencies = gulp.src('extensions/node_modules/**', { base: '.' }); + + const marketplaceExtensions = es.merge( + ...builtInExtensions + .filter(({ name }) => opts.desiredExtensions ? opts.desiredExtensions.indexOf(name) >= 0 : true) + .map(extension => { + return fromMarketplace(extension.name, extension.version) + .pipe(rename(p => p.dirname = `extensions/${extension.name}/${p.dirname}`)); + }) + ); + + return es.merge(localExtensions, localExtensionDependencies, marketplaceExtensions) + .pipe(util2.setExecutableBit(['**/*.sh'])) + .pipe(filter(['**', '!**/*.js.map'])); +} \ No newline at end of file