@theia/native-webpack-plugin 1.47.1 → 1.48.1

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.
package/README.md CHANGED
@@ -1,29 +1,29 @@
1
- <div align='center'>
2
-
3
- <br />
4
-
5
- <img src='https://raw.githubusercontent.com/eclipse-theia/theia/master/logo/theia.svg?sanitize=true' alt='theia-ext-logo' width='100px' />
6
-
7
- <h2>ECLIPSE THEIA - NATIVE-WEBPACK-PLUGIN</h2>
8
-
9
- <hr />
10
-
11
- </div>
12
-
13
- ## Description
14
-
15
- The `@theia/native-webpack-plugin` package contains a webpack plugin that is used to handle native dependencies for bundling Theia based application backends.
16
-
17
- ## Additional Information
18
-
19
- - [Theia - GitHub](https://github.com/eclipse-theia/theia)
20
- - [Theia - Website](https://theia-ide.org/)
21
-
22
- ## License
23
-
24
- - [Eclipse Public License 2.0](http://www.eclipse.org/legal/epl-2.0/)
25
- - [一 (Secondary) GNU General Public License, version 2 with the GNU Classpath Exception](https://projects.eclipse.org/license/secondary-gpl-2.0-cp)
26
-
27
- ## Trademark
28
- "Theia" is a trademark of the Eclipse Foundation
29
- https://www.eclipse.org/theia
1
+ <div align='center'>
2
+
3
+ <br />
4
+
5
+ <img src='https://raw.githubusercontent.com/eclipse-theia/theia/master/logo/theia.svg?sanitize=true' alt='theia-ext-logo' width='100px' />
6
+
7
+ <h2>ECLIPSE THEIA - NATIVE-WEBPACK-PLUGIN</h2>
8
+
9
+ <hr />
10
+
11
+ </div>
12
+
13
+ ## Description
14
+
15
+ The `@theia/native-webpack-plugin` package contains a webpack plugin that is used to handle native dependencies for bundling Theia based application backends.
16
+
17
+ ## Additional Information
18
+
19
+ - [Theia - GitHub](https://github.com/eclipse-theia/theia)
20
+ - [Theia - Website](https://theia-ide.org/)
21
+
22
+ ## License
23
+
24
+ - [Eclipse Public License 2.0](http://www.eclipse.org/legal/epl-2.0/)
25
+ - [一 (Secondary) GNU General Public License, version 2 with the GNU Classpath Exception](https://projects.eclipse.org/license/secondary-gpl-2.0-cp)
26
+
27
+ ## Trademark
28
+ "Theia" is a trademark of the Eclipse Foundation
29
+ https://www.eclipse.org/theia
package/lib/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import { NativeWebpackPlugin } from './native-webpack-plugin';
2
- export = NativeWebpackPlugin;
1
+ import { NativeWebpackPlugin } from './native-webpack-plugin';
2
+ export = NativeWebpackPlugin;
3
3
  //# sourceMappingURL=index.d.ts.map
package/lib/index.js CHANGED
@@ -1,19 +1,19 @@
1
- "use strict";
2
- // *****************************************************************************
3
- // Copyright (C) 2023 TypeFox and others.
4
- //
5
- // This program and the accompanying materials are made available under the
6
- // terms of the Eclipse Public License v. 2.0 which is available at
7
- // http://www.eclipse.org/legal/epl-2.0.
8
- //
9
- // This Source Code may also be made available under the following Secondary
10
- // Licenses when the conditions for such availability set forth in the Eclipse
11
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
- // with the GNU Classpath Exception which is available at
13
- // https://www.gnu.org/software/classpath/license.html.
14
- //
15
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
16
- // *****************************************************************************
17
- const native_webpack_plugin_1 = require("./native-webpack-plugin");
18
- module.exports = native_webpack_plugin_1.NativeWebpackPlugin;
1
+ "use strict";
2
+ // *****************************************************************************
3
+ // Copyright (C) 2023 TypeFox and others.
4
+ //
5
+ // This program and the accompanying materials are made available under the
6
+ // terms of the Eclipse Public License v. 2.0 which is available at
7
+ // http://www.eclipse.org/legal/epl-2.0.
8
+ //
9
+ // This Source Code may also be made available under the following Secondary
10
+ // Licenses when the conditions for such availability set forth in the Eclipse
11
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
+ // with the GNU Classpath Exception which is available at
13
+ // https://www.gnu.org/software/classpath/license.html.
14
+ //
15
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
16
+ // *****************************************************************************
17
+ const native_webpack_plugin_1 = require("./native-webpack-plugin");
18
+ module.exports = native_webpack_plugin_1.NativeWebpackPlugin;
19
19
  //# sourceMappingURL=index.js.map
@@ -1,21 +1,21 @@
1
- import type { Compiler } from 'webpack';
2
- export interface NativeWebpackPluginOptions {
3
- out: string;
4
- trash: boolean;
5
- ripgrep: boolean;
6
- pty: boolean;
7
- replacements?: Record<string, string>;
8
- nativeBindings?: Record<string, string>;
9
- }
10
- export declare class NativeWebpackPlugin {
11
- private bindings;
12
- private options;
13
- constructor(options: NativeWebpackPluginOptions);
14
- nativeBinding(dependency: string, nodePath: string): void;
15
- apply(compiler: Compiler): void;
16
- protected copyRipgrep(compiler: Compiler): Promise<void>;
17
- protected copyNodePtySpawnHelper(compiler: Compiler): Promise<void>;
18
- protected copyTrashHelper(compiler: Compiler): Promise<void>;
19
- protected copyExecutable(source: string, target: string): Promise<void>;
20
- }
1
+ import type { Compiler } from 'webpack';
2
+ export interface NativeWebpackPluginOptions {
3
+ out: string;
4
+ trash: boolean;
5
+ ripgrep: boolean;
6
+ pty: boolean;
7
+ replacements?: Record<string, string>;
8
+ nativeBindings?: Record<string, string>;
9
+ }
10
+ export declare class NativeWebpackPlugin {
11
+ private bindings;
12
+ private options;
13
+ constructor(options: NativeWebpackPluginOptions);
14
+ nativeBinding(dependency: string, nodePath: string): void;
15
+ apply(compiler: Compiler): void;
16
+ protected copyRipgrep(compiler: Compiler): Promise<void>;
17
+ protected copyNodePtySpawnHelper(compiler: Compiler): Promise<void>;
18
+ protected copyTrashHelper(compiler: Compiler): Promise<void>;
19
+ protected copyExecutable(source: string, target: string): Promise<void>;
20
+ }
21
21
  //# sourceMappingURL=native-webpack-plugin.d.ts.map
@@ -1,161 +1,161 @@
1
- "use strict";
2
- // *****************************************************************************
3
- // Copyright (C) 2023 TypeFox and others.
4
- //
5
- // This program and the accompanying materials are made available under the
6
- // terms of the Eclipse Public License v. 2.0 which is available at
7
- // http://www.eclipse.org/legal/epl-2.0.
8
- //
9
- // This Source Code may also be made available under the following Secondary
10
- // Licenses when the conditions for such availability set forth in the Eclipse
11
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
- // with the GNU Classpath Exception which is available at
13
- // https://www.gnu.org/software/classpath/license.html.
14
- //
15
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
16
- // *****************************************************************************
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.NativeWebpackPlugin = void 0;
19
- const path = require("path");
20
- const fs = require("fs");
21
- const os = require("os");
22
- const REQUIRE_RIPGREP = '@vscode/ripgrep';
23
- const REQUIRE_VSCODE_WINDOWS_CA_CERTS = '@vscode/windows-ca-certs';
24
- const REQUIRE_BINDINGS = 'bindings';
25
- const REQUIRE_KEYMAPPING = './build/Release/keymapping';
26
- class NativeWebpackPlugin {
27
- constructor(options) {
28
- var _a;
29
- this.bindings = new Map();
30
- this.options = options;
31
- for (const [name, value] of Object.entries((_a = options.nativeBindings) !== null && _a !== void 0 ? _a : {})) {
32
- this.nativeBinding(name, value);
33
- }
34
- }
35
- nativeBinding(dependency, nodePath) {
36
- this.bindings.set(dependency, nodePath);
37
- }
38
- apply(compiler) {
39
- let replacements = {};
40
- compiler.hooks.initialize.tap(NativeWebpackPlugin.name, async () => {
41
- var _a;
42
- const directory = path.resolve(compiler.outputPath, 'native-webpack-plugin');
43
- if (fs.existsSync(directory)) {
44
- await fs.promises.rm(directory, {
45
- force: true,
46
- recursive: true
47
- });
48
- }
49
- await fs.promises.mkdir(directory, {
50
- recursive: true
51
- });
52
- const bindingsFile = await buildFile(directory, 'bindings.js', bindingsReplacement(Array.from(this.bindings.entries())));
53
- const ripgrepFile = await buildFile(directory, 'ripgrep.js', ripgrepReplacement(this.options.out));
54
- const keymappingFile = './build/Release/keymapping.node';
55
- const windowsCaCertsFile = '@vscode/windows-ca-certs/build/Release/crypt32.node';
56
- replacements = {
57
- ...((_a = this.options.replacements) !== null && _a !== void 0 ? _a : {}),
58
- [REQUIRE_RIPGREP]: ripgrepFile,
59
- [REQUIRE_BINDINGS]: bindingsFile,
60
- [REQUIRE_KEYMAPPING]: keymappingFile,
61
- [REQUIRE_VSCODE_WINDOWS_CA_CERTS]: windowsCaCertsFile
62
- };
63
- });
64
- compiler.hooks.normalModuleFactory.tap(NativeWebpackPlugin.name, nmf => {
65
- nmf.hooks.beforeResolve.tap(NativeWebpackPlugin.name, result => {
66
- for (const [file, replacement] of Object.entries(replacements)) {
67
- if (result.request === file) {
68
- result.request = replacement;
69
- }
70
- }
71
- });
72
- nmf.hooks.afterResolve.tap(NativeWebpackPlugin.name, result => {
73
- const createData = result.createData;
74
- for (const [file, replacement] of Object.entries(replacements)) {
75
- if (createData.resource === file) {
76
- createData.resource = replacement;
77
- }
78
- }
79
- });
80
- });
81
- compiler.hooks.afterEmit.tapPromise(NativeWebpackPlugin.name, async () => {
82
- if (this.options.trash) {
83
- await this.copyTrashHelper(compiler);
84
- }
85
- if (this.options.ripgrep) {
86
- await this.copyRipgrep(compiler);
87
- }
88
- if (this.options.pty) {
89
- await this.copyNodePtySpawnHelper(compiler);
90
- }
91
- });
92
- }
93
- async copyRipgrep(compiler) {
94
- const suffix = process.platform === 'win32' ? '.exe' : '';
95
- const sourceFile = require.resolve(`@vscode/ripgrep/bin/rg${suffix}`);
96
- const targetFile = path.join(compiler.outputPath, this.options.out, `rg${suffix}`);
97
- await this.copyExecutable(sourceFile, targetFile);
98
- }
99
- async copyNodePtySpawnHelper(compiler) {
100
- const targetDirectory = path.resolve(compiler.outputPath, '..', 'build', 'Release');
101
- if (process.platform === 'win32') {
102
- const agentFile = require.resolve('node-pty/build/Release/winpty-agent.exe');
103
- const targetAgentFile = path.join(targetDirectory, 'winpty-agent.exe');
104
- await this.copyExecutable(agentFile, targetAgentFile);
105
- const dllFile = require.resolve('node-pty/build/Release/winpty.dll');
106
- const targetDllFile = path.join(targetDirectory, 'winpty.dll');
107
- await this.copyExecutable(dllFile, targetDllFile);
108
- }
109
- else {
110
- const sourceFile = require.resolve('node-pty/build/Release/spawn-helper');
111
- const targetFile = path.join(targetDirectory, 'spawn-helper');
112
- await this.copyExecutable(sourceFile, targetFile);
113
- }
114
- }
115
- async copyTrashHelper(compiler) {
116
- let sourceFile;
117
- let targetFile;
118
- if (process.platform === 'win32') {
119
- sourceFile = require.resolve('trash/lib/windows-trash.exe');
120
- targetFile = path.join(compiler.outputPath, 'windows-trash.exe');
121
- }
122
- else if (process.platform === 'darwin') {
123
- sourceFile = require.resolve('trash/lib/macos-trash');
124
- targetFile = path.join(compiler.outputPath, 'macos-trash');
125
- }
126
- if (sourceFile && targetFile) {
127
- await this.copyExecutable(sourceFile, targetFile);
128
- }
129
- }
130
- async copyExecutable(source, target) {
131
- const targetDirectory = path.dirname(target);
132
- await fs.promises.mkdir(targetDirectory, { recursive: true });
133
- await fs.promises.copyFile(source, target);
134
- await fs.promises.chmod(target, 0o777);
135
- }
136
- }
137
- exports.NativeWebpackPlugin = NativeWebpackPlugin;
138
- async function buildFile(root, name, content) {
139
- const tmpFile = path.join(root, name);
140
- await fs.promises.writeFile(tmpFile, content);
141
- return tmpFile;
142
- }
143
- const ripgrepReplacement = (nativePath = '.') => `
144
- const path = require('path');
145
-
146
- exports.rgPath = path.join(__dirname, \`./${nativePath}/rg\${process.platform === 'win32' ? '.exe' : ''}\`);
147
- `;
148
- const bindingsReplacement = (entries) => {
149
- const cases = [];
150
- for (const [module, node] of entries) {
151
- cases.push(`${' '.repeat(8)}case '${module}': return require('${node}');`);
152
- }
153
- return `
154
- module.exports = function (jsModule) {
155
- switch (jsModule) {
156
- ${cases.join(os.EOL)}
157
- }
158
- throw new Error(\`unhandled module: "\${jsModule}"\`);
159
- }`.trim();
160
- };
1
+ "use strict";
2
+ // *****************************************************************************
3
+ // Copyright (C) 2023 TypeFox and others.
4
+ //
5
+ // This program and the accompanying materials are made available under the
6
+ // terms of the Eclipse Public License v. 2.0 which is available at
7
+ // http://www.eclipse.org/legal/epl-2.0.
8
+ //
9
+ // This Source Code may also be made available under the following Secondary
10
+ // Licenses when the conditions for such availability set forth in the Eclipse
11
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
+ // with the GNU Classpath Exception which is available at
13
+ // https://www.gnu.org/software/classpath/license.html.
14
+ //
15
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
16
+ // *****************************************************************************
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.NativeWebpackPlugin = void 0;
19
+ const path = require("path");
20
+ const fs = require("fs");
21
+ const os = require("os");
22
+ const REQUIRE_RIPGREP = '@vscode/ripgrep';
23
+ const REQUIRE_VSCODE_WINDOWS_CA_CERTS = '@vscode/windows-ca-certs';
24
+ const REQUIRE_BINDINGS = 'bindings';
25
+ const REQUIRE_KEYMAPPING = './build/Release/keymapping';
26
+ class NativeWebpackPlugin {
27
+ constructor(options) {
28
+ var _a;
29
+ this.bindings = new Map();
30
+ this.options = options;
31
+ for (const [name, value] of Object.entries((_a = options.nativeBindings) !== null && _a !== void 0 ? _a : {})) {
32
+ this.nativeBinding(name, value);
33
+ }
34
+ }
35
+ nativeBinding(dependency, nodePath) {
36
+ this.bindings.set(dependency, nodePath);
37
+ }
38
+ apply(compiler) {
39
+ let replacements = {};
40
+ compiler.hooks.initialize.tap(NativeWebpackPlugin.name, async () => {
41
+ var _a;
42
+ const directory = path.resolve(compiler.outputPath, 'native-webpack-plugin');
43
+ if (fs.existsSync(directory)) {
44
+ await fs.promises.rm(directory, {
45
+ force: true,
46
+ recursive: true
47
+ });
48
+ }
49
+ await fs.promises.mkdir(directory, {
50
+ recursive: true
51
+ });
52
+ const bindingsFile = await buildFile(directory, 'bindings.js', bindingsReplacement(Array.from(this.bindings.entries())));
53
+ const ripgrepFile = await buildFile(directory, 'ripgrep.js', ripgrepReplacement(this.options.out));
54
+ const keymappingFile = './build/Release/keymapping.node';
55
+ const windowsCaCertsFile = '@vscode/windows-ca-certs/build/Release/crypt32.node';
56
+ replacements = {
57
+ ...((_a = this.options.replacements) !== null && _a !== void 0 ? _a : {}),
58
+ [REQUIRE_RIPGREP]: ripgrepFile,
59
+ [REQUIRE_BINDINGS]: bindingsFile,
60
+ [REQUIRE_KEYMAPPING]: keymappingFile,
61
+ [REQUIRE_VSCODE_WINDOWS_CA_CERTS]: windowsCaCertsFile
62
+ };
63
+ });
64
+ compiler.hooks.normalModuleFactory.tap(NativeWebpackPlugin.name, nmf => {
65
+ nmf.hooks.beforeResolve.tap(NativeWebpackPlugin.name, result => {
66
+ for (const [file, replacement] of Object.entries(replacements)) {
67
+ if (result.request === file) {
68
+ result.request = replacement;
69
+ }
70
+ }
71
+ });
72
+ nmf.hooks.afterResolve.tap(NativeWebpackPlugin.name, result => {
73
+ const createData = result.createData;
74
+ for (const [file, replacement] of Object.entries(replacements)) {
75
+ if (createData.resource === file) {
76
+ createData.resource = replacement;
77
+ }
78
+ }
79
+ });
80
+ });
81
+ compiler.hooks.afterEmit.tapPromise(NativeWebpackPlugin.name, async () => {
82
+ if (this.options.trash) {
83
+ await this.copyTrashHelper(compiler);
84
+ }
85
+ if (this.options.ripgrep) {
86
+ await this.copyRipgrep(compiler);
87
+ }
88
+ if (this.options.pty) {
89
+ await this.copyNodePtySpawnHelper(compiler);
90
+ }
91
+ });
92
+ }
93
+ async copyRipgrep(compiler) {
94
+ const suffix = process.platform === 'win32' ? '.exe' : '';
95
+ const sourceFile = require.resolve(`@vscode/ripgrep/bin/rg${suffix}`);
96
+ const targetFile = path.join(compiler.outputPath, this.options.out, `rg${suffix}`);
97
+ await this.copyExecutable(sourceFile, targetFile);
98
+ }
99
+ async copyNodePtySpawnHelper(compiler) {
100
+ const targetDirectory = path.resolve(compiler.outputPath, '..', 'build', 'Release');
101
+ if (process.platform === 'win32') {
102
+ const agentFile = require.resolve('node-pty/build/Release/winpty-agent.exe');
103
+ const targetAgentFile = path.join(targetDirectory, 'winpty-agent.exe');
104
+ await this.copyExecutable(agentFile, targetAgentFile);
105
+ const dllFile = require.resolve('node-pty/build/Release/winpty.dll');
106
+ const targetDllFile = path.join(targetDirectory, 'winpty.dll');
107
+ await this.copyExecutable(dllFile, targetDllFile);
108
+ }
109
+ else {
110
+ const sourceFile = require.resolve('node-pty/build/Release/spawn-helper');
111
+ const targetFile = path.join(targetDirectory, 'spawn-helper');
112
+ await this.copyExecutable(sourceFile, targetFile);
113
+ }
114
+ }
115
+ async copyTrashHelper(compiler) {
116
+ let sourceFile;
117
+ let targetFile;
118
+ if (process.platform === 'win32') {
119
+ sourceFile = require.resolve('trash/lib/windows-trash.exe');
120
+ targetFile = path.join(compiler.outputPath, 'windows-trash.exe');
121
+ }
122
+ else if (process.platform === 'darwin') {
123
+ sourceFile = require.resolve('trash/lib/macos-trash');
124
+ targetFile = path.join(compiler.outputPath, 'macos-trash');
125
+ }
126
+ if (sourceFile && targetFile) {
127
+ await this.copyExecutable(sourceFile, targetFile);
128
+ }
129
+ }
130
+ async copyExecutable(source, target) {
131
+ const targetDirectory = path.dirname(target);
132
+ await fs.promises.mkdir(targetDirectory, { recursive: true });
133
+ await fs.promises.copyFile(source, target);
134
+ await fs.promises.chmod(target, 0o777);
135
+ }
136
+ }
137
+ exports.NativeWebpackPlugin = NativeWebpackPlugin;
138
+ async function buildFile(root, name, content) {
139
+ const tmpFile = path.join(root, name);
140
+ await fs.promises.writeFile(tmpFile, content);
141
+ return tmpFile;
142
+ }
143
+ const ripgrepReplacement = (nativePath = '.') => `
144
+ const path = require('path');
145
+
146
+ exports.rgPath = path.join(__dirname, \`./${nativePath}/rg\${process.platform === 'win32' ? '.exe' : ''}\`);
147
+ `;
148
+ const bindingsReplacement = (entries) => {
149
+ const cases = [];
150
+ for (const [module, node] of entries) {
151
+ cases.push(`${' '.repeat(8)}case '${module}': return require('${node}');`);
152
+ }
153
+ return `
154
+ module.exports = function (jsModule) {
155
+ switch (jsModule) {
156
+ ${cases.join(os.EOL)}
157
+ }
158
+ throw new Error(\`unhandled module: "\${jsModule}"\`);
159
+ }`.trim();
160
+ };
161
161
  //# sourceMappingURL=native-webpack-plugin.js.map
@@ -1,26 +1,26 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2023 TypeFox and others.
3
- //
4
- // This program and the accompanying materials are made available under the
5
- // terms of the Eclipse Public License v. 2.0 which is available at
6
- // http://www.eclipse.org/legal/epl-2.0.
7
- //
8
- // This Source Code may also be made available under the following Secondary
9
- // Licenses when the conditions for such availability set forth in the Eclipse
10
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
- // with the GNU Classpath Exception which is available at
12
- // https://www.gnu.org/software/classpath/license.html.
13
- //
14
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
- /* note: this bogus test file is required so that
17
- we are able to run mocha unit tests on this
18
- package, without having any actual unit tests in it.
19
- This way a coverage report will be generated,
20
- showing 0% coverage, instead of no report.
21
- This file can be removed once we have real unit
22
- tests in place. */
23
- describe('request package', () => {
24
- it('should support code coverage statistics', () => true);
25
- });
1
+ // *****************************************************************************
2
+ // Copyright (C) 2023 TypeFox and others.
3
+ //
4
+ // This program and the accompanying materials are made available under the
5
+ // terms of the Eclipse Public License v. 2.0 which is available at
6
+ // http://www.eclipse.org/legal/epl-2.0.
7
+ //
8
+ // This Source Code may also be made available under the following Secondary
9
+ // Licenses when the conditions for such availability set forth in the Eclipse
10
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ // with the GNU Classpath Exception which is available at
12
+ // https://www.gnu.org/software/classpath/license.html.
13
+ //
14
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+ /* note: this bogus test file is required so that
17
+ we are able to run mocha unit tests on this
18
+ package, without having any actual unit tests in it.
19
+ This way a coverage report will be generated,
20
+ showing 0% coverage, instead of no report.
21
+ This file can be removed once we have real unit
22
+ tests in place. */
23
+ describe('request package', () => {
24
+ it('should support code coverage statistics', () => true);
25
+ });
26
26
  //# sourceMappingURL=package.spec.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theia/native-webpack-plugin",
3
- "version": "1.47.1",
3
+ "version": "1.48.1",
4
4
  "description": "Webpack Plugin for native dependencies of Theia.",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -32,5 +32,5 @@
32
32
  "tslib": "^2.6.2",
33
33
  "webpack": "^5.76.0"
34
34
  },
35
- "gitHead": "ddc29054061700e54fe819f147a7ec335a6d8037"
35
+ "gitHead": "04c631933dfd14f58d1df5b9b28dd5596c84ec04"
36
36
  }
package/src/index.ts CHANGED
@@ -1,18 +1,18 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2023 TypeFox and others.
3
- //
4
- // This program and the accompanying materials are made available under the
5
- // terms of the Eclipse Public License v. 2.0 which is available at
6
- // http://www.eclipse.org/legal/epl-2.0.
7
- //
8
- // This Source Code may also be made available under the following Secondary
9
- // Licenses when the conditions for such availability set forth in the Eclipse
10
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
- // with the GNU Classpath Exception which is available at
12
- // https://www.gnu.org/software/classpath/license.html.
13
- //
14
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- import { NativeWebpackPlugin } from './native-webpack-plugin';
18
- export = NativeWebpackPlugin;
1
+ // *****************************************************************************
2
+ // Copyright (C) 2023 TypeFox and others.
3
+ //
4
+ // This program and the accompanying materials are made available under the
5
+ // terms of the Eclipse Public License v. 2.0 which is available at
6
+ // http://www.eclipse.org/legal/epl-2.0.
7
+ //
8
+ // This Source Code may also be made available under the following Secondary
9
+ // Licenses when the conditions for such availability set forth in the Eclipse
10
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ // with the GNU Classpath Exception which is available at
12
+ // https://www.gnu.org/software/classpath/license.html.
13
+ //
14
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import { NativeWebpackPlugin } from './native-webpack-plugin';
18
+ export = NativeWebpackPlugin;
@@ -1,183 +1,183 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2023 TypeFox and others.
3
- //
4
- // This program and the accompanying materials are made available under the
5
- // terms of the Eclipse Public License v. 2.0 which is available at
6
- // http://www.eclipse.org/legal/epl-2.0.
7
- //
8
- // This Source Code may also be made available under the following Secondary
9
- // Licenses when the conditions for such availability set forth in the Eclipse
10
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
- // with the GNU Classpath Exception which is available at
12
- // https://www.gnu.org/software/classpath/license.html.
13
- //
14
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- import * as path from 'path';
18
- import * as fs from 'fs';
19
- import * as os from 'os';
20
-
21
- import type { Compiler } from 'webpack';
22
-
23
- const REQUIRE_RIPGREP = '@vscode/ripgrep';
24
- const REQUIRE_VSCODE_WINDOWS_CA_CERTS = '@vscode/windows-ca-certs';
25
- const REQUIRE_BINDINGS = 'bindings';
26
- const REQUIRE_KEYMAPPING = './build/Release/keymapping';
27
-
28
- export interface NativeWebpackPluginOptions {
29
- out: string;
30
- trash: boolean;
31
- ripgrep: boolean;
32
- pty: boolean;
33
- replacements?: Record<string, string>;
34
- nativeBindings?: Record<string, string>;
35
- }
36
-
37
- export class NativeWebpackPlugin {
38
-
39
- private bindings = new Map<string, string>();
40
- private options: NativeWebpackPluginOptions;
41
-
42
- constructor(options: NativeWebpackPluginOptions) {
43
- this.options = options;
44
- for (const [name, value] of Object.entries(options.nativeBindings ?? {})) {
45
- this.nativeBinding(name, value);
46
- }
47
- }
48
-
49
- nativeBinding(dependency: string, nodePath: string): void {
50
- this.bindings.set(dependency, nodePath);
51
- }
52
-
53
- apply(compiler: Compiler): void {
54
- let replacements: Record<string, string> = {};
55
- compiler.hooks.initialize.tap(NativeWebpackPlugin.name, async () => {
56
- const directory = path.resolve(compiler.outputPath, 'native-webpack-plugin');
57
- if (fs.existsSync(directory)) {
58
- await fs.promises.rm(directory, {
59
- force: true,
60
- recursive: true
61
- });
62
- }
63
- await fs.promises.mkdir(directory, {
64
- recursive: true
65
- });
66
- const bindingsFile = await buildFile(directory, 'bindings.js', bindingsReplacement(Array.from(this.bindings.entries())));
67
- const ripgrepFile = await buildFile(directory, 'ripgrep.js', ripgrepReplacement(this.options.out));
68
- const keymappingFile = './build/Release/keymapping.node';
69
- const windowsCaCertsFile = '@vscode/windows-ca-certs/build/Release/crypt32.node';
70
- replacements = {
71
- ...(this.options.replacements ?? {}),
72
- [REQUIRE_RIPGREP]: ripgrepFile,
73
- [REQUIRE_BINDINGS]: bindingsFile,
74
- [REQUIRE_KEYMAPPING]: keymappingFile,
75
- [REQUIRE_VSCODE_WINDOWS_CA_CERTS]: windowsCaCertsFile
76
- };
77
- });
78
- compiler.hooks.normalModuleFactory.tap(
79
- NativeWebpackPlugin.name,
80
- nmf => {
81
- nmf.hooks.beforeResolve.tap(NativeWebpackPlugin.name, result => {
82
- for (const [file, replacement] of Object.entries(replacements)) {
83
- if (result.request === file) {
84
- result.request = replacement;
85
- }
86
- }
87
- });
88
- nmf.hooks.afterResolve.tap(NativeWebpackPlugin.name, result => {
89
- const createData = result.createData;
90
- for (const [file, replacement] of Object.entries(replacements)) {
91
- if (createData.resource === file) {
92
- createData.resource = replacement;
93
- }
94
- }
95
- });
96
- }
97
- );
98
- compiler.hooks.afterEmit.tapPromise(NativeWebpackPlugin.name, async () => {
99
- if (this.options.trash) {
100
- await this.copyTrashHelper(compiler);
101
- }
102
- if (this.options.ripgrep) {
103
- await this.copyRipgrep(compiler);
104
- }
105
- if (this.options.pty) {
106
- await this.copyNodePtySpawnHelper(compiler);
107
- }
108
- });
109
- }
110
-
111
- protected async copyRipgrep(compiler: Compiler): Promise<void> {
112
- const suffix = process.platform === 'win32' ? '.exe' : '';
113
- const sourceFile = require.resolve(`@vscode/ripgrep/bin/rg${suffix}`);
114
- const targetFile = path.join(compiler.outputPath, this.options.out, `rg${suffix}`);
115
- await this.copyExecutable(sourceFile, targetFile);
116
- }
117
-
118
- protected async copyNodePtySpawnHelper(compiler: Compiler): Promise<void> {
119
- const targetDirectory = path.resolve(compiler.outputPath, '..', 'build', 'Release');
120
- if (process.platform === 'win32') {
121
- const agentFile = require.resolve('node-pty/build/Release/winpty-agent.exe');
122
- const targetAgentFile = path.join(targetDirectory, 'winpty-agent.exe');
123
- await this.copyExecutable(agentFile, targetAgentFile);
124
- const dllFile = require.resolve('node-pty/build/Release/winpty.dll');
125
- const targetDllFile = path.join(targetDirectory, 'winpty.dll');
126
- await this.copyExecutable(dllFile, targetDllFile);
127
- } else {
128
- const sourceFile = require.resolve('node-pty/build/Release/spawn-helper');
129
- const targetFile = path.join(targetDirectory, 'spawn-helper');
130
- await this.copyExecutable(sourceFile, targetFile);
131
- }
132
- }
133
-
134
- protected async copyTrashHelper(compiler: Compiler): Promise<void> {
135
- let sourceFile: string | undefined;
136
- let targetFile: string | undefined;
137
- if (process.platform === 'win32') {
138
- sourceFile = require.resolve('trash/lib/windows-trash.exe');
139
- targetFile = path.join(compiler.outputPath, 'windows-trash.exe');
140
- } else if (process.platform === 'darwin') {
141
- sourceFile = require.resolve('trash/lib/macos-trash');
142
- targetFile = path.join(compiler.outputPath, 'macos-trash');
143
- }
144
- if (sourceFile && targetFile) {
145
- await this.copyExecutable(sourceFile, targetFile);
146
- }
147
- }
148
-
149
- protected async copyExecutable(source: string, target: string): Promise<void> {
150
- const targetDirectory = path.dirname(target);
151
- await fs.promises.mkdir(targetDirectory, { recursive: true });
152
- await fs.promises.copyFile(source, target);
153
- await fs.promises.chmod(target, 0o777);
154
- }
155
- }
156
-
157
- async function buildFile(root: string, name: string, content: string): Promise<string> {
158
- const tmpFile = path.join(root, name);
159
- await fs.promises.writeFile(tmpFile, content);
160
- return tmpFile;
161
- }
162
-
163
- const ripgrepReplacement = (nativePath: string = '.'): string => `
164
- const path = require('path');
165
-
166
- exports.rgPath = path.join(__dirname, \`./${nativePath}/rg\${process.platform === 'win32' ? '.exe' : ''}\`);
167
- `;
168
-
169
- const bindingsReplacement = (entries: [string, string][]): string => {
170
- const cases: string[] = [];
171
-
172
- for (const [module, node] of entries) {
173
- cases.push(`${' '.repeat(8)}case '${module}': return require('${node}');`);
174
- }
175
-
176
- return `
177
- module.exports = function (jsModule) {
178
- switch (jsModule) {
179
- ${cases.join(os.EOL)}
180
- }
181
- throw new Error(\`unhandled module: "\${jsModule}"\`);
182
- }`.trim();
183
- };
1
+ // *****************************************************************************
2
+ // Copyright (C) 2023 TypeFox and others.
3
+ //
4
+ // This program and the accompanying materials are made available under the
5
+ // terms of the Eclipse Public License v. 2.0 which is available at
6
+ // http://www.eclipse.org/legal/epl-2.0.
7
+ //
8
+ // This Source Code may also be made available under the following Secondary
9
+ // Licenses when the conditions for such availability set forth in the Eclipse
10
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ // with the GNU Classpath Exception which is available at
12
+ // https://www.gnu.org/software/classpath/license.html.
13
+ //
14
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import * as path from 'path';
18
+ import * as fs from 'fs';
19
+ import * as os from 'os';
20
+
21
+ import type { Compiler } from 'webpack';
22
+
23
+ const REQUIRE_RIPGREP = '@vscode/ripgrep';
24
+ const REQUIRE_VSCODE_WINDOWS_CA_CERTS = '@vscode/windows-ca-certs';
25
+ const REQUIRE_BINDINGS = 'bindings';
26
+ const REQUIRE_KEYMAPPING = './build/Release/keymapping';
27
+
28
+ export interface NativeWebpackPluginOptions {
29
+ out: string;
30
+ trash: boolean;
31
+ ripgrep: boolean;
32
+ pty: boolean;
33
+ replacements?: Record<string, string>;
34
+ nativeBindings?: Record<string, string>;
35
+ }
36
+
37
+ export class NativeWebpackPlugin {
38
+
39
+ private bindings = new Map<string, string>();
40
+ private options: NativeWebpackPluginOptions;
41
+
42
+ constructor(options: NativeWebpackPluginOptions) {
43
+ this.options = options;
44
+ for (const [name, value] of Object.entries(options.nativeBindings ?? {})) {
45
+ this.nativeBinding(name, value);
46
+ }
47
+ }
48
+
49
+ nativeBinding(dependency: string, nodePath: string): void {
50
+ this.bindings.set(dependency, nodePath);
51
+ }
52
+
53
+ apply(compiler: Compiler): void {
54
+ let replacements: Record<string, string> = {};
55
+ compiler.hooks.initialize.tap(NativeWebpackPlugin.name, async () => {
56
+ const directory = path.resolve(compiler.outputPath, 'native-webpack-plugin');
57
+ if (fs.existsSync(directory)) {
58
+ await fs.promises.rm(directory, {
59
+ force: true,
60
+ recursive: true
61
+ });
62
+ }
63
+ await fs.promises.mkdir(directory, {
64
+ recursive: true
65
+ });
66
+ const bindingsFile = await buildFile(directory, 'bindings.js', bindingsReplacement(Array.from(this.bindings.entries())));
67
+ const ripgrepFile = await buildFile(directory, 'ripgrep.js', ripgrepReplacement(this.options.out));
68
+ const keymappingFile = './build/Release/keymapping.node';
69
+ const windowsCaCertsFile = '@vscode/windows-ca-certs/build/Release/crypt32.node';
70
+ replacements = {
71
+ ...(this.options.replacements ?? {}),
72
+ [REQUIRE_RIPGREP]: ripgrepFile,
73
+ [REQUIRE_BINDINGS]: bindingsFile,
74
+ [REQUIRE_KEYMAPPING]: keymappingFile,
75
+ [REQUIRE_VSCODE_WINDOWS_CA_CERTS]: windowsCaCertsFile
76
+ };
77
+ });
78
+ compiler.hooks.normalModuleFactory.tap(
79
+ NativeWebpackPlugin.name,
80
+ nmf => {
81
+ nmf.hooks.beforeResolve.tap(NativeWebpackPlugin.name, result => {
82
+ for (const [file, replacement] of Object.entries(replacements)) {
83
+ if (result.request === file) {
84
+ result.request = replacement;
85
+ }
86
+ }
87
+ });
88
+ nmf.hooks.afterResolve.tap(NativeWebpackPlugin.name, result => {
89
+ const createData = result.createData;
90
+ for (const [file, replacement] of Object.entries(replacements)) {
91
+ if (createData.resource === file) {
92
+ createData.resource = replacement;
93
+ }
94
+ }
95
+ });
96
+ }
97
+ );
98
+ compiler.hooks.afterEmit.tapPromise(NativeWebpackPlugin.name, async () => {
99
+ if (this.options.trash) {
100
+ await this.copyTrashHelper(compiler);
101
+ }
102
+ if (this.options.ripgrep) {
103
+ await this.copyRipgrep(compiler);
104
+ }
105
+ if (this.options.pty) {
106
+ await this.copyNodePtySpawnHelper(compiler);
107
+ }
108
+ });
109
+ }
110
+
111
+ protected async copyRipgrep(compiler: Compiler): Promise<void> {
112
+ const suffix = process.platform === 'win32' ? '.exe' : '';
113
+ const sourceFile = require.resolve(`@vscode/ripgrep/bin/rg${suffix}`);
114
+ const targetFile = path.join(compiler.outputPath, this.options.out, `rg${suffix}`);
115
+ await this.copyExecutable(sourceFile, targetFile);
116
+ }
117
+
118
+ protected async copyNodePtySpawnHelper(compiler: Compiler): Promise<void> {
119
+ const targetDirectory = path.resolve(compiler.outputPath, '..', 'build', 'Release');
120
+ if (process.platform === 'win32') {
121
+ const agentFile = require.resolve('node-pty/build/Release/winpty-agent.exe');
122
+ const targetAgentFile = path.join(targetDirectory, 'winpty-agent.exe');
123
+ await this.copyExecutable(agentFile, targetAgentFile);
124
+ const dllFile = require.resolve('node-pty/build/Release/winpty.dll');
125
+ const targetDllFile = path.join(targetDirectory, 'winpty.dll');
126
+ await this.copyExecutable(dllFile, targetDllFile);
127
+ } else {
128
+ const sourceFile = require.resolve('node-pty/build/Release/spawn-helper');
129
+ const targetFile = path.join(targetDirectory, 'spawn-helper');
130
+ await this.copyExecutable(sourceFile, targetFile);
131
+ }
132
+ }
133
+
134
+ protected async copyTrashHelper(compiler: Compiler): Promise<void> {
135
+ let sourceFile: string | undefined;
136
+ let targetFile: string | undefined;
137
+ if (process.platform === 'win32') {
138
+ sourceFile = require.resolve('trash/lib/windows-trash.exe');
139
+ targetFile = path.join(compiler.outputPath, 'windows-trash.exe');
140
+ } else if (process.platform === 'darwin') {
141
+ sourceFile = require.resolve('trash/lib/macos-trash');
142
+ targetFile = path.join(compiler.outputPath, 'macos-trash');
143
+ }
144
+ if (sourceFile && targetFile) {
145
+ await this.copyExecutable(sourceFile, targetFile);
146
+ }
147
+ }
148
+
149
+ protected async copyExecutable(source: string, target: string): Promise<void> {
150
+ const targetDirectory = path.dirname(target);
151
+ await fs.promises.mkdir(targetDirectory, { recursive: true });
152
+ await fs.promises.copyFile(source, target);
153
+ await fs.promises.chmod(target, 0o777);
154
+ }
155
+ }
156
+
157
+ async function buildFile(root: string, name: string, content: string): Promise<string> {
158
+ const tmpFile = path.join(root, name);
159
+ await fs.promises.writeFile(tmpFile, content);
160
+ return tmpFile;
161
+ }
162
+
163
+ const ripgrepReplacement = (nativePath: string = '.'): string => `
164
+ const path = require('path');
165
+
166
+ exports.rgPath = path.join(__dirname, \`./${nativePath}/rg\${process.platform === 'win32' ? '.exe' : ''}\`);
167
+ `;
168
+
169
+ const bindingsReplacement = (entries: [string, string][]): string => {
170
+ const cases: string[] = [];
171
+
172
+ for (const [module, node] of entries) {
173
+ cases.push(`${' '.repeat(8)}case '${module}': return require('${node}');`);
174
+ }
175
+
176
+ return `
177
+ module.exports = function (jsModule) {
178
+ switch (jsModule) {
179
+ ${cases.join(os.EOL)}
180
+ }
181
+ throw new Error(\`unhandled module: "\${jsModule}"\`);
182
+ }`.trim();
183
+ };
@@ -1,28 +1,28 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2023 TypeFox and others.
3
- //
4
- // This program and the accompanying materials are made available under the
5
- // terms of the Eclipse Public License v. 2.0 which is available at
6
- // http://www.eclipse.org/legal/epl-2.0.
7
- //
8
- // This Source Code may also be made available under the following Secondary
9
- // Licenses when the conditions for such availability set forth in the Eclipse
10
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
- // with the GNU Classpath Exception which is available at
12
- // https://www.gnu.org/software/classpath/license.html.
13
- //
14
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- /* note: this bogus test file is required so that
18
- we are able to run mocha unit tests on this
19
- package, without having any actual unit tests in it.
20
- This way a coverage report will be generated,
21
- showing 0% coverage, instead of no report.
22
- This file can be removed once we have real unit
23
- tests in place. */
24
-
25
- describe('request package', () => {
26
-
27
- it('should support code coverage statistics', () => true);
28
- });
1
+ // *****************************************************************************
2
+ // Copyright (C) 2023 TypeFox and others.
3
+ //
4
+ // This program and the accompanying materials are made available under the
5
+ // terms of the Eclipse Public License v. 2.0 which is available at
6
+ // http://www.eclipse.org/legal/epl-2.0.
7
+ //
8
+ // This Source Code may also be made available under the following Secondary
9
+ // Licenses when the conditions for such availability set forth in the Eclipse
10
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ // with the GNU Classpath Exception which is available at
12
+ // https://www.gnu.org/software/classpath/license.html.
13
+ //
14
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ /* note: this bogus test file is required so that
18
+ we are able to run mocha unit tests on this
19
+ package, without having any actual unit tests in it.
20
+ This way a coverage report will be generated,
21
+ showing 0% coverage, instead of no report.
22
+ This file can be removed once we have real unit
23
+ tests in place. */
24
+
25
+ describe('request package', () => {
26
+
27
+ it('should support code coverage statistics', () => true);
28
+ });