Skip to content

Commit 9886f60

Browse files
committed
republish built-in VS Code extensions to npmjs under @theia/vscode-builtin- prefix
Signed-off-by: Anton Kosyakov <anton.kosyakov@typefox.io>
1 parent ceef8cb commit 9886f60

11 files changed

+179
-52
lines changed

.gitpod.yml

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
image:
22
file: Dockerfile
3-
ports:
4-
- port: 3000
53
tasks:
64
- init: yarn

README.md

+9-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
This extension contributes built-in VS Code extensions to Theia.
44

5-
## Getting started
5+
[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/theia-ide/vscode-builtin-extensions)
6+
7+
## Getting started (locally)
68

79
Install [nvm](https://github.com/creationix/nvm#install-script).
810

@@ -17,15 +19,18 @@ Install yarn.
1719

1820
npm install -g yarn
1921

22+
Install vscode.
23+
24+
cd vscode-builtin-extensions
25+
git submodule init
26+
git submodule update
27+
2028
Install vscode prerequisite dependencies.
2129

2230
https://github.com/Microsoft/vscode/wiki/How-to-Contribute#prerequisites
2331

2432
## Build
2533

26-
cd vscode-builtin-extensions
27-
git submodule init
28-
git submodule update
2934
yarn
3035

3136
## Running the browser example

bundle-extensions.js

-44
This file was deleted.

package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,18 @@
44
"prepare": "yarn build:extensions && yarn bundle:extensions && yarn build",
55
"build": "lerna run prepare",
66
"build:extensions": "cd vscode && yarn && npx gulp compile-extensions-build",
7-
"bundle:extensions": "cd vscode && node ../bundle-extensions.js",
7+
"bundle:extensions": "node ./src/bundle.js",
8+
"republish:extensions": "node ./src/republish.js",
89
"rebuild:browser": "theia rebuild:browser",
910
"rebuild:electron": "theia rebuild:electron"
1011
},
1112
"devDependencies": {
13+
"@types/node": "^8.0.0",
1214
"lerna": "2.4.0"
1315
},
1416
"workspaces": [
1517
"vscode-builtin-extensions",
1618
"browser-app",
1719
"electron-app"
1820
]
19-
}
21+
}

src/bundle.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// @ts-check
2+
const { src, vscode, run } = require('./paths.js')
3+
module.exports = run('node', [src('vscode-bundle.js')], vscode());

src/paths.js

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// @ts-check
2+
const path = require('path');
3+
const cp = require('child_process');
4+
5+
/**
6+
* @type {(paths: string[]) => string}
7+
*/
8+
function root(...paths) {
9+
return path.join(__dirname, '..', ...paths);
10+
}
11+
/**
12+
* @type {(paths: string[]) => string}
13+
*/
14+
function src(...paths) {
15+
return root('src', ...paths);
16+
}
17+
/**
18+
* @type {(paths: string[]) => string}
19+
*/
20+
function vscode(...paths) {
21+
return root('vscode', ...paths);
22+
}
23+
/**
24+
* @type {(paths: string[]) => string}
25+
*/
26+
function theiaExtension(...paths) {
27+
return root('vscode-builtin-extensions', ...paths);
28+
}
29+
/**
30+
* @type {(paths: string[]) => string}
31+
*/
32+
function extensions(...paths) {
33+
return theiaExtension('extensions', ...paths);
34+
}
35+
36+
/**
37+
* @type {(command: string, args?: ReadonlyArray<string>, cwd?: string) => Promise<string>}
38+
*/
39+
function run(command, args, cwd = process.cwd()) {
40+
return new Promise((resolve, reject) => {
41+
let result = '';
42+
const p = cp.spawn(command, args, { cwd });
43+
p.stdout.on('data', data => {
44+
console.log(String(data));
45+
result += String(data);
46+
});
47+
p.stderr.on('data', data => console.error(String(data)));
48+
p.on('close', code => !code ? resolve(result) : reject());
49+
});
50+
}
51+
52+
module.exports = { root, src, vscode, theiaExtension, extensions, run };

src/publish.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// @ts-check
2+
const rimraf = require('../vscode/node_modules/rimraf');
3+
const { extensions } = require('./paths.js');
4+
5+
(async () => {
6+
await require('./bundle.js');
7+
// see why exlcuded https://github.com/theia-ide/theia/issues/3815#issuecomment-452686623
8+
rimraf.sync(extensions('configuration-editing'));
9+
rimraf.sync(extensions('css-language-features'));
10+
rimraf.sync(extensions('html-language-features'));
11+
rimraf.sync(extensions('extension-editing'));
12+
rimraf.sync(extensions('grunt'));
13+
rimraf.sync(extensions('gulp'));
14+
})();

src/republish.js

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* Republish built-in VS Code extensions to npmjs under `@theia/vscode-builtin-` prefix.
3+
*/
4+
// @ts-check
5+
const fs = require('fs');
6+
const os = require('os');
7+
const { extensions, run } = require('./paths.js');
8+
9+
(async () => {
10+
await require('./bundle.js');
11+
const result = [];
12+
for (const extension of await fs.readdirSync(extensions())) {
13+
if (extension.startsWith('ms-vscode')) {
14+
// skip marketplace extensions
15+
continue;
16+
}
17+
const pckPath = extensions(extension, 'package.json');
18+
if (!fs.existsSync(pckPath)) {
19+
continue;
20+
}
21+
const originalContent = fs.readFileSync(pckPath, 'utf-8');
22+
const pck = JSON.parse(originalContent);
23+
pck.name = '@theia/vscode-builtin-' + pck.name;
24+
// bump to publish
25+
pck.version = '0.1.0';
26+
27+
console.log(pck.name, ': publishing...');
28+
try {
29+
fs.writeFileSync(pckPath, JSON.stringify(pck, undefined, 2), 'utf-8');
30+
await run('yarn', ['publish', '--access', 'public', '--ignore-scripts'], extensions(extension));
31+
result.push(pck.name + ': sucessfully published');
32+
} catch (e) {
33+
result.push(pck.name + ': failed to publish');
34+
if (e) {
35+
console.error(e)
36+
};
37+
} finally {
38+
fs.writeFileSync(pckPath, originalContent, 'utf-8');
39+
}
40+
}
41+
console.log(result.join(os.EOL));
42+
})();

src/vscode-bundle.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// @ts-check
2+
const fs = require('fs');
3+
const rimraf = require('../vscode/node_modules/rimraf');
4+
const vfs = require('../vscode/node_modules/vinyl-fs');
5+
const ext = require('../vscode/build/lib/extensions');
6+
const { root, theiaExtension, extensions, run } = require('./paths.js')
7+
8+
const backupNodeModules = () => {
9+
const move = (src, dest) => fs.existsSync(src) && fs.renameSync(src, dest);
10+
const nodeModules = root('node_modules');
11+
const nodeModulesBackup = root('node_modules_backup');
12+
move(nodeModules, nodeModulesBackup);
13+
return () => move(nodeModulesBackup, nodeModules);
14+
}
15+
const revertNodeModules = backupNodeModules();
16+
process.on('exit', revertNodeModules);
17+
process.on('SIGINT', revertNodeModules);
18+
process.on('SIGTERM', revertNodeModules);
19+
rimraf.sync(extensions());
20+
(async () => {
21+
const stream = ext.packageExtensionsStream().pipe(vfs.dest(theiaExtension()));
22+
await new Promise((resolve, reject) => {
23+
stream.on('error', reject);
24+
stream.on('end', resolve);
25+
});
26+
await run('yarn', ['install', '--production'], extensions('debug-auto-launch'));
27+
await run('yarn', ['install', '--production'], extensions('ms-vscode.node-debug'));
28+
await run('yarn', ['install', '--production'], extensions('ms-vscode.node-debug2'));
29+
})();
30+

tsconfig.json

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"compilerOptions": {
3+
"experimentalDecorators": true,
4+
"noUnusedLocals": true,
5+
"emitDecoratorMetadata": true,
6+
"downlevelIteration": true,
7+
"module": "commonjs",
8+
"moduleResolution": "node",
9+
"target": "es5",
10+
"lib": [
11+
"es6"
12+
],
13+
"sourceMap": true,
14+
"rootDir": "src",
15+
"allowJs": true
16+
},
17+
"include": [
18+
"src"
19+
]
20+
}

yarn.lock

+5
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,11 @@
645645
resolved "https://registry.yarnpkg.com/@types/node/-/node-10.12.18.tgz#1d3ca764718915584fcd9f6344621b7672665c67"
646646
integrity sha512-fh+pAqt4xRzPfqA6eh3Z2y6fyZavRIumvjhaCL753+TVkGKGhpPeyrJG2JftD0T9q4GF00KjefsQ+PQNDdWQaQ==
647647

648+
"@types/node@^8.0.0":
649+
version "8.10.42"
650+
resolved "https://registry.yarnpkg.com/@types/node/-/node-8.10.42.tgz#d3d8e738e13540a09b3f4a714dac1ffbf8939f7d"
651+
integrity sha512-8LCqostMfYwQs9by1k21/P4KZp9uFQk3Q528y3qtPKQnCJmKz0Em3YzgeNjTNV1FVrG/7n/6j12d4UKg9zSgDw==
652+
648653
"@types/node@^8.0.24":
649654
version "8.10.39"
650655
resolved "https://registry.yarnpkg.com/@types/node/-/node-8.10.39.tgz#e7e87ad00364dd7bc485c940926345b8ec1a26ca"

0 commit comments

Comments
 (0)