@vscode/test-web 0.0.13 → 0.0.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,78 +1,78 @@
1
- "use strict";
2
- /*---------------------------------------------------------------------------------------------
3
- * Copyright (c) Microsoft Corporation. All rights reserved.
4
- * Licensed under the MIT License. See License.txt in the project root for license information.
5
- *--------------------------------------------------------------------------------------------*/
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.configureMounts = exports.fsProviderFolderUri = exports.fsProviderExtensionPrefix = void 0;
8
- const kstatic = require("koa-static");
9
- const kmount = require("koa-mount");
10
- const Router = require("@koa/router");
11
- const fs_1 = require("fs");
12
- const path = require("path");
13
- const mountPrefix = '/static/mount';
14
- exports.fsProviderExtensionPrefix = '/static/fsproviderextension';
15
- exports.fsProviderFolderUri = 'vscode-test-web://mount/';
16
- function configureMounts(config, app) {
17
- const folderMountPath = config.folderMountPath;
18
- if (folderMountPath) {
19
- console.log(`Serving local content ${folderMountPath} at ${mountPrefix}`);
20
- app.use(fileOps(mountPrefix, folderMountPath));
21
- app.use(kmount(mountPrefix, kstatic(folderMountPath, { hidden: true })));
22
- app.use(kmount(exports.fsProviderExtensionPrefix, kstatic(path.join(__dirname, '../../fs-provider'), { hidden: true })));
23
- }
24
- }
25
- exports.configureMounts = configureMounts;
26
- function fileOps(mountPrefix, folderMountPath) {
27
- const router = new Router();
28
- router.get(`${mountPrefix}(/.*)?`, async (ctx, next) => {
29
- if (ctx.query.stat !== undefined) {
30
- const p = path.join(folderMountPath, ctx.path.substring(mountPrefix.length));
31
- try {
32
- const stats = await fs_1.promises.stat(p);
33
- ctx.body = {
34
- type: getFileType(stats),
35
- ctime: stats.ctime.getTime(),
36
- mtime: stats.mtime.getTime(),
37
- size: stats.size
38
- };
39
- }
40
- catch (e) {
41
- ctx.body = { error: e.code };
42
- }
43
- }
44
- else if (ctx.query.readdir !== undefined) {
45
- const p = path.join(folderMountPath, ctx.path.substring(mountPrefix.length));
46
- try {
47
- const entries = await fs_1.promises.readdir(p, { withFileTypes: true });
48
- ctx.body = entries.map(d => ({ name: d.name, type: getFileType(d) }));
49
- }
50
- catch (e) {
51
- ctx.body = { error: e.code };
52
- }
53
- }
54
- else {
55
- return next();
56
- }
57
- });
58
- return router.routes();
59
- }
60
- var FileType;
61
- (function (FileType) {
62
- FileType[FileType["Unknown"] = 0] = "Unknown";
63
- FileType[FileType["File"] = 1] = "File";
64
- FileType[FileType["Directory"] = 2] = "Directory";
65
- FileType[FileType["SymbolicLink"] = 64] = "SymbolicLink";
66
- })(FileType || (FileType = {}));
67
- function getFileType(stats) {
68
- if (stats.isFile()) {
69
- return FileType.File;
70
- }
71
- else if (stats.isDirectory()) {
72
- return FileType.Directory;
73
- }
74
- else if (stats.isSymbolicLink()) {
75
- return FileType.SymbolicLink;
76
- }
77
- return FileType.Unknown;
78
- }
1
+ "use strict";
2
+ /*---------------------------------------------------------------------------------------------
3
+ * Copyright (c) Microsoft Corporation. All rights reserved.
4
+ * Licensed under the MIT License. See License.txt in the project root for license information.
5
+ *--------------------------------------------------------------------------------------------*/
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.configureMounts = exports.fsProviderFolderUri = exports.fsProviderExtensionPrefix = void 0;
8
+ const kstatic = require("koa-static");
9
+ const kmount = require("koa-mount");
10
+ const Router = require("@koa/router");
11
+ const fs_1 = require("fs");
12
+ const path = require("path");
13
+ const mountPrefix = '/static/mount';
14
+ exports.fsProviderExtensionPrefix = '/static/extensions/fs';
15
+ exports.fsProviderFolderUri = 'vscode-test-web://mount/';
16
+ function configureMounts(config, app) {
17
+ const folderMountPath = config.folderMountPath;
18
+ if (folderMountPath) {
19
+ console.log(`Serving local content ${folderMountPath} at ${mountPrefix}`);
20
+ app.use(fileOps(mountPrefix, folderMountPath));
21
+ app.use(kmount(mountPrefix, kstatic(folderMountPath, { hidden: true })));
22
+ app.use(kmount(exports.fsProviderExtensionPrefix, kstatic(path.join(__dirname, '../../fs-provider'), { hidden: true })));
23
+ }
24
+ }
25
+ exports.configureMounts = configureMounts;
26
+ function fileOps(mountPrefix, folderMountPath) {
27
+ const router = new Router();
28
+ router.get(`${mountPrefix}(/.*)?`, async (ctx, next) => {
29
+ if (ctx.query.stat !== undefined) {
30
+ const p = path.join(folderMountPath, ctx.path.substring(mountPrefix.length));
31
+ try {
32
+ const stats = await fs_1.promises.stat(p);
33
+ ctx.body = {
34
+ type: getFileType(stats),
35
+ ctime: stats.ctime.getTime(),
36
+ mtime: stats.mtime.getTime(),
37
+ size: stats.size
38
+ };
39
+ }
40
+ catch (e) {
41
+ ctx.body = { error: e.code };
42
+ }
43
+ }
44
+ else if (ctx.query.readdir !== undefined) {
45
+ const p = path.join(folderMountPath, ctx.path.substring(mountPrefix.length));
46
+ try {
47
+ const entries = await fs_1.promises.readdir(p, { withFileTypes: true });
48
+ ctx.body = entries.map(d => ({ name: d.name, type: getFileType(d) }));
49
+ }
50
+ catch (e) {
51
+ ctx.body = { error: e.code };
52
+ }
53
+ }
54
+ else {
55
+ return next();
56
+ }
57
+ });
58
+ return router.routes();
59
+ }
60
+ var FileType;
61
+ (function (FileType) {
62
+ FileType[FileType["Unknown"] = 0] = "Unknown";
63
+ FileType[FileType["File"] = 1] = "File";
64
+ FileType[FileType["Directory"] = 2] = "Directory";
65
+ FileType[FileType["SymbolicLink"] = 64] = "SymbolicLink";
66
+ })(FileType || (FileType = {}));
67
+ function getFileType(stats) {
68
+ if (stats.isFile()) {
69
+ return FileType.File;
70
+ }
71
+ else if (stats.isDirectory()) {
72
+ return FileType.Directory;
73
+ }
74
+ else if (stats.isSymbolicLink()) {
75
+ return FileType.SymbolicLink;
76
+ }
77
+ return FileType.Unknown;
78
+ }
@@ -1,147 +1,112 @@
1
- "use strict";
2
- /*---------------------------------------------------------------------------------------------
3
- * Copyright (c) Microsoft Corporation. All rights reserved.
4
- * Licensed under the MIT License. See License.txt in the project root for license information.
5
- *--------------------------------------------------------------------------------------------*/
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- const path = require("path");
8
- const fs_1 = require("fs");
9
- const vscode_uri_1 = require("vscode-uri");
10
- const Router = require("@koa/router");
11
- const extensions_1 = require("./extensions");
12
- const download_1 = require("./download");
13
- const mounts_1 = require("./mounts");
14
- function asJSON(value) {
15
- return JSON.stringify(value).replace(/"/g, '"');
16
- }
17
- class Workbench {
18
- constructor(baseUrl, dev, builtInExtensions = []) {
19
- this.baseUrl = baseUrl;
20
- this.dev = dev;
21
- this.builtInExtensions = builtInExtensions;
22
- }
23
- async render(workbenchWebConfiguration) {
24
- const values = {
25
- WORKBENCH_WEB_CONFIGURATION: asJSON(workbenchWebConfiguration),
26
- WORKBENCH_AUTH_SESSION: '',
27
- WORKBENCH_WEB_BASE_URL: this.baseUrl,
28
- WORKBENCH_BUILTIN_EXTENSIONS: asJSON(this.builtInExtensions),
29
- WORKBENCH_MAIN: this.getMain()
30
- };
31
- try {
32
- const workbenchTemplate = (await fs_1.promises.readFile(path.resolve(__dirname, '../../views/workbench.html'))).toString();
33
- return workbenchTemplate.replace(/\{\{([^}]+)\}\}/g, (_, key) => { var _a; return (_a = values[key]) !== null && _a !== void 0 ? _a : 'undefined'; });
34
- }
35
- catch (e) {
36
- return String(e);
37
- }
38
- }
39
- getMain() {
40
- return this.dev
41
- ? `<script> require(['vs/code/browser/workbench/workbench'], function() {}); </script>`
42
- : `<script src="${this.baseUrl}/out/vs/workbench/workbench.web.api.nls.js"></script>`
43
- + `<script src="${this.baseUrl}/out/vs/workbench/workbench.web.api.js"></script>`
44
- + `<script src="${this.baseUrl}/out/vs/code/browser/workbench/workbench.js"></script>`;
45
- }
46
- async renderCallback() {
47
- return await (0, download_1.fetch)(`${this.baseUrl}/out/vs/code/browser/workbench/callback.html`);
48
- }
49
- }
50
- function valueOrFirst(value) {
51
- return Array.isArray(value) ? value[0] : value;
52
- }
53
- async function getWorkbenchOptions(ctx, config) {
54
- const options = {};
55
- if (config.extensionPath) {
56
- options.additionalBuiltinExtensions = await (0, extensions_1.scanForExtensions)(config.extensionPath, {
57
- scheme: ctx.protocol,
58
- authority: ctx.host,
59
- path: '/static/extensions',
60
- });
61
- }
62
- if (config.extensionDevelopmentPath) {
63
- const developmentOptions = options.developmentOptions = {};
64
- developmentOptions.extensions = await (0, extensions_1.scanForExtensions)(config.extensionDevelopmentPath, { scheme: ctx.protocol, authority: ctx.host, path: '/static/devextensions' });
65
- if (config.extensionTestsPath) {
66
- let relativePath = path.relative(config.extensionDevelopmentPath, config.extensionTestsPath);
67
- if (process.platform === 'win32') {
68
- relativePath = relativePath.replace(/\\/g, '/');
69
- }
70
- developmentOptions.extensionTestsPath = {
71
- scheme: ctx.protocol,
72
- authority: ctx.host,
73
- path: path.posix.join('/static/devextensions', relativePath),
74
- };
75
- }
76
- }
77
- if (config.folderMountPath) {
78
- if (!options.additionalBuiltinExtensions) {
79
- options.additionalBuiltinExtensions = [];
80
- }
81
- options.additionalBuiltinExtensions.push({ scheme: ctx.protocol, authority: ctx.host, path: mounts_1.fsProviderExtensionPrefix });
82
- options.folderUri = vscode_uri_1.URI.parse(mounts_1.fsProviderFolderUri);
83
- }
84
- else if (config.folderUri) {
85
- options.folderUri = vscode_uri_1.URI.parse(config.folderUri);
86
- }
87
- return options;
88
- }
89
- function default_1(config) {
90
- const router = new Router();
91
- router.use(async (ctx, next) => {
92
- if (ctx.query['dev'] || config.build.type === 'sources') {
93
- try {
94
- const builtInExtensions = await (0, download_1.fetchJSON)('http://localhost:8080/builtin');
95
- ctx.state.workbench = new Workbench('http://localhost:8080/static', true, builtInExtensions);
96
- }
97
- catch (err) {
98
- console.log(err);
99
- ctx.throw('Could not connect to localhost:8080, make sure you start `yarn web`', 400);
100
- }
101
- }
102
- else if (config.build.type === 'static') {
103
- ctx.state.workbench = new Workbench(`${ctx.protocol}://${ctx.host}/static/build`, false);
104
- }
105
- else if (config.build.type === 'cdn') {
106
- ctx.state.workbench = new Workbench(config.build.uri, false);
107
- }
108
- await next();
109
- });
110
- const callbacks = new Map();
111
- router.get('/callback', async (ctx) => {
112
- const { 'vscode-requestId': vscodeRequestId, 'vscode-scheme': vscodeScheme, 'vscode-authority': vscodeAuthority, 'vscode-path': vscodePath, 'vscode-query': vscodeQuery, 'vscode-fragment': vscodeFragment, } = ctx.query;
113
- if (!vscodeRequestId || !vscodeScheme || !vscodeAuthority) {
114
- return ctx.throw(400);
115
- }
116
- const requestId = valueOrFirst(vscodeRequestId);
117
- const uri = vscode_uri_1.URI.from({
118
- scheme: valueOrFirst(vscodeScheme),
119
- authority: valueOrFirst(vscodeAuthority),
120
- path: valueOrFirst(vscodePath),
121
- query: valueOrFirst(vscodeQuery),
122
- fragment: valueOrFirst(vscodeFragment),
123
- });
124
- callbacks.set(requestId, uri);
125
- ctx.body = await ctx.state.workbench.renderCallback();
126
- });
127
- router.get('/fetch-callback', async (ctx) => {
128
- const { 'vscode-requestId': vscodeRequestId } = ctx.query;
129
- if (!vscodeRequestId) {
130
- return ctx.throw(400);
131
- }
132
- const requestId = valueOrFirst(vscodeRequestId);
133
- const uri = callbacks.get(requestId);
134
- if (!uri) {
135
- return ctx.throw(400);
136
- }
137
- callbacks.delete(requestId);
138
- ctx.body = uri.toJSON();
139
- });
140
- router.get('/', async (ctx) => {
141
- const options = await getWorkbenchOptions(ctx, config);
142
- ctx.body = await ctx.state.workbench.render(options);
143
- });
144
- //mountAPI(config, router);
145
- return router.routes();
146
- }
147
- exports.default = default_1;
1
+ "use strict";
2
+ /*---------------------------------------------------------------------------------------------
3
+ * Copyright (c) Microsoft Corporation. All rights reserved.
4
+ * Licensed under the MIT License. See License.txt in the project root for license information.
5
+ *--------------------------------------------------------------------------------------------*/
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ const path = require("path");
8
+ const fs_1 = require("fs");
9
+ const vscode_uri_1 = require("vscode-uri");
10
+ const Router = require("@koa/router");
11
+ const extensions_1 = require("./extensions");
12
+ const download_1 = require("./download");
13
+ const mounts_1 = require("./mounts");
14
+ function asJSON(value) {
15
+ return JSON.stringify(value).replace(/"/g, '&quot;');
16
+ }
17
+ class Workbench {
18
+ constructor(baseUrl, dev, builtInExtensions = []) {
19
+ this.baseUrl = baseUrl;
20
+ this.dev = dev;
21
+ this.builtInExtensions = builtInExtensions;
22
+ }
23
+ async render(workbenchWebConfiguration) {
24
+ const values = {
25
+ WORKBENCH_WEB_CONFIGURATION: asJSON(workbenchWebConfiguration),
26
+ WORKBENCH_AUTH_SESSION: '',
27
+ WORKBENCH_WEB_BASE_URL: this.baseUrl,
28
+ WORKBENCH_BUILTIN_EXTENSIONS: asJSON(this.builtInExtensions),
29
+ WORKBENCH_MAIN: this.getMain()
30
+ };
31
+ try {
32
+ const workbenchTemplate = (await fs_1.promises.readFile(path.resolve(__dirname, '../../views/workbench.html'))).toString();
33
+ return workbenchTemplate.replace(/\{\{([^}]+)\}\}/g, (_, key) => { var _a; return (_a = values[key]) !== null && _a !== void 0 ? _a : 'undefined'; });
34
+ }
35
+ catch (e) {
36
+ return String(e);
37
+ }
38
+ }
39
+ getMain() {
40
+ return this.dev
41
+ ? `<script> require(['vs/code/browser/workbench/workbench'], function() {}); </script>`
42
+ : `<script src="${this.baseUrl}/out/vs/workbench/workbench.web.api.nls.js"></script>`
43
+ + `<script src="${this.baseUrl}/out/vs/workbench/workbench.web.api.js"></script>`
44
+ + `<script src="${this.baseUrl}/out/vs/code/browser/workbench/workbench.js"></script>`;
45
+ }
46
+ async renderCallback() {
47
+ return await (0, download_1.fetch)(`${this.baseUrl}/out/vs/code/browser/workbench/callback.html`);
48
+ }
49
+ }
50
+ async function getWorkbenchOptions(ctx, config) {
51
+ const options = {};
52
+ if (config.extensionPaths) {
53
+ await Promise.all(config.extensionPaths.map(async (extensionPath, index) => {
54
+ options.additionalBuiltinExtensions = await (0, extensions_1.scanForExtensions)(extensionPath, {
55
+ scheme: ctx.protocol,
56
+ authority: ctx.host,
57
+ path: `/static/extensions/${index}`,
58
+ });
59
+ }));
60
+ }
61
+ if (config.extensionDevelopmentPath) {
62
+ const developmentOptions = options.developmentOptions = {};
63
+ developmentOptions.extensions = await (0, extensions_1.scanForExtensions)(config.extensionDevelopmentPath, { scheme: ctx.protocol, authority: ctx.host, path: '/static/devextensions' });
64
+ if (config.extensionTestsPath) {
65
+ let relativePath = path.relative(config.extensionDevelopmentPath, config.extensionTestsPath);
66
+ if (process.platform === 'win32') {
67
+ relativePath = relativePath.replace(/\\/g, '/');
68
+ }
69
+ developmentOptions.extensionTestsPath = {
70
+ scheme: ctx.protocol,
71
+ authority: ctx.host,
72
+ path: path.posix.join('/static/devextensions', relativePath),
73
+ };
74
+ }
75
+ }
76
+ if (config.folderMountPath) {
77
+ if (!options.additionalBuiltinExtensions) {
78
+ options.additionalBuiltinExtensions = [];
79
+ }
80
+ options.additionalBuiltinExtensions.push({ scheme: ctx.protocol, authority: ctx.host, path: mounts_1.fsProviderExtensionPrefix });
81
+ options.folderUri = vscode_uri_1.URI.parse(mounts_1.fsProviderFolderUri);
82
+ }
83
+ else if (config.folderUri) {
84
+ options.folderUri = vscode_uri_1.URI.parse(config.folderUri);
85
+ }
86
+ return options;
87
+ }
88
+ function default_1(config) {
89
+ const router = new Router();
90
+ router.use(async (ctx, next) => {
91
+ if (config.build.type === 'sources') {
92
+ const builtInExtensions = await (0, extensions_1.getScannedBuiltinExtensions)(config.build.location);
93
+ ctx.state.workbench = new Workbench(`${ctx.protocol}://${ctx.host}/static/sources`, true, builtInExtensions);
94
+ }
95
+ else if (config.build.type === 'static') {
96
+ ctx.state.workbench = new Workbench(`${ctx.protocol}://${ctx.host}/static/build`, false);
97
+ }
98
+ else if (config.build.type === 'cdn') {
99
+ ctx.state.workbench = new Workbench(config.build.uri, false);
100
+ }
101
+ await next();
102
+ });
103
+ router.get('/callback', async (ctx) => {
104
+ ctx.body = await ctx.state.workbench.renderCallback();
105
+ });
106
+ router.get('/', async (ctx) => {
107
+ const options = await getWorkbenchOptions(ctx, config);
108
+ ctx.body = await ctx.state.workbench.render(options);
109
+ });
110
+ return router.routes();
111
+ }
112
+ exports.default = default_1;
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@vscode/test-web",
3
- "version": "0.0.13",
3
+ "version": "0.0.17",
4
4
  "scripts": {
5
- "init": "yarn --cwd=fs-provider && yarn --cwd=sample",
5
+ "install-extensions": "yarn --cwd=fs-provider && yarn --cwd=sample",
6
6
  "compile": "tsc -p ./ && yarn compile-fs-provider",
7
7
  "watch": "tsc -w -p ./",
8
8
  "prepublishOnly": "yarn compile",
@@ -11,7 +11,7 @@
11
11
  "postversion": "git push && git push --tags",
12
12
  "compile-fs-provider": "yarn --cwd=fs-provider compile-web",
13
13
  "compile-sample": "yarn --cwd=sample compile-web",
14
- "sample": "npm run compile && npm run compile-sample && node . --extensionDevelopmentPath=sample --browserType=chromium sample/test-workspace",
14
+ "sample": "npm run compile && npm run compile-sample && node . --extensionDevelopmentPath=sample --browserType=chromium --verbose sample/test-workspace",
15
15
  "sample-tests": "npm run compile && npm run compile-sample && node . --extensionDevelopmentPath=sample --extensionTestsPath=sample/dist/web/test/suite/index.js --browserType=chromium --headless=false sample/test-workspace"
16
16
  },
17
17
  "main": "./out/index.js",
@@ -7,6 +7,12 @@
7
7
  </script>
8
8
  <meta charset="utf-8" />
9
9
 
10
+ <!-- Mobile tweaks -->
11
+ <meta name="mobile-web-app-capable" content="yes" />
12
+ <meta name="apple-mobile-web-app-capable" content="yes" />
13
+ <meta name="apple-mobile-web-app-title" content="Code">
14
+ <link rel="apple-touch-icon" href="{{WORKBENCH_WEB_BASE_URL}}/code-192.png" />
15
+
10
16
  <!-- Disable pinch zooming -->
11
17
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
12
18