@theia/native-webpack-plugin 1.39.0-next.19

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 ADDED
@@ -0,0 +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
package/lib/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import { NativeWebpackPlugin } from './native-webpack-plugin';
2
+ export = NativeWebpackPlugin;
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAC9D,SAAS,mBAAmB,CAAC"}
package/lib/index.js ADDED
@@ -0,0 +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;
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,yCAAyC;AACzC,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;AAEhF,mEAA8D;AAC9D,iBAAS,2CAAmB,CAAC"}
@@ -0,0 +1,20 @@
1
+ import type { Compiler } from 'webpack';
2
+ export interface NativeWebpackPluginOptions {
3
+ out: string;
4
+ ripgrep: boolean;
5
+ pty: boolean;
6
+ replacements?: Record<string, string>;
7
+ nativeBindings?: Record<string, string>;
8
+ }
9
+ export declare class NativeWebpackPlugin {
10
+ private bindings;
11
+ private options;
12
+ private tracker;
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 copyExecutable(source: string, target: string): Promise<void>;
19
+ }
20
+ //# sourceMappingURL=native-webpack-plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"native-webpack-plugin.d.ts","sourceRoot":"","sources":["../src/native-webpack-plugin.ts"],"names":[],"mappings":"AAqBA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAOxC,MAAM,WAAW,0BAA0B;IACvC,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,OAAO,CAAC;IACjB,GAAG,EAAE,OAAO,CAAC;IACb,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACtC,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC3C;AAED,qBAAa,mBAAmB;IAE5B,OAAO,CAAC,QAAQ,CAA6B;IAC7C,OAAO,CAAC,OAAO,CAA6B;IAC5C,OAAO,CAAC,OAAO,CAAc;gBAEjB,OAAO,EAAE,0BAA0B;IAQ/C,aAAa,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI;IAIzD,KAAK,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI;cAoDf,WAAW,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;cAO9C,sBAAsB,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;cAgBzD,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAMhF"}
@@ -0,0 +1,136 @@
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 temp = require("temp");
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
+ class NativeWebpackPlugin {
28
+ constructor(options) {
29
+ var _a;
30
+ this.bindings = new Map();
31
+ this.options = options;
32
+ this.tracker = temp.track();
33
+ for (const [name, value] of Object.entries((_a = options.nativeBindings) !== null && _a !== void 0 ? _a : {})) {
34
+ this.nativeBinding(name, value);
35
+ }
36
+ }
37
+ nativeBinding(dependency, nodePath) {
38
+ this.bindings.set(dependency, nodePath);
39
+ }
40
+ apply(compiler) {
41
+ let replacements = {};
42
+ compiler.hooks.initialize.tap(NativeWebpackPlugin.name, () => {
43
+ var _a;
44
+ const directory = this.tracker.mkdirSync({
45
+ dir: path.resolve(compiler.outputPath, 'native-webpack-plugin')
46
+ });
47
+ const bindingsFile = buildFile(directory, 'bindings.js', bindingsReplacement(Array.from(this.bindings.entries())));
48
+ const ripgrepFile = buildFile(directory, 'ripgrep.js', ripgrepReplacement(this.options.out));
49
+ const keymappingFile = './build/Release/keymapping.node';
50
+ const windowsCaCertsFile = '@vscode/windows-ca-certs/build/Release/crypt32.node';
51
+ replacements = Object.assign(Object.assign({}, ((_a = this.options.replacements) !== null && _a !== void 0 ? _a : {})), { [REQUIRE_RIPGREP]: ripgrepFile, [REQUIRE_BINDINGS]: bindingsFile, [REQUIRE_KEYMAPPING]: keymappingFile, [REQUIRE_VSCODE_WINDOWS_CA_CERTS]: windowsCaCertsFile });
52
+ });
53
+ compiler.hooks.normalModuleFactory.tap(NativeWebpackPlugin.name, nmf => {
54
+ nmf.hooks.beforeResolve.tap(NativeWebpackPlugin.name, result => {
55
+ for (const [file, replacement] of Object.entries(replacements)) {
56
+ if (result.request === file) {
57
+ result.request = replacement;
58
+ }
59
+ }
60
+ });
61
+ nmf.hooks.afterResolve.tap(NativeWebpackPlugin.name, result => {
62
+ const createData = result.createData;
63
+ for (const [file, replacement] of Object.entries(replacements)) {
64
+ if (createData.resource === file) {
65
+ createData.resource = replacement;
66
+ }
67
+ }
68
+ });
69
+ });
70
+ compiler.hooks.afterEmit.tapAsync(NativeWebpackPlugin.name, async () => {
71
+ if (this.options.ripgrep) {
72
+ await this.copyRipgrep(compiler);
73
+ }
74
+ if (this.options.pty) {
75
+ await this.copyNodePtySpawnHelper(compiler);
76
+ }
77
+ this.tracker.cleanupSync();
78
+ });
79
+ compiler.hooks.failed.tap(NativeWebpackPlugin.name, async () => {
80
+ this.tracker.cleanupSync();
81
+ });
82
+ }
83
+ async copyRipgrep(compiler) {
84
+ const suffix = process.platform === 'win32' ? '.exe' : '';
85
+ const sourceFile = require.resolve(`@vscode/ripgrep/bin/rg${suffix}`);
86
+ const targetFile = path.join(compiler.outputPath, this.options.out, `rg${suffix}`);
87
+ await this.copyExecutable(sourceFile, targetFile);
88
+ }
89
+ async copyNodePtySpawnHelper(compiler) {
90
+ const targetDirectory = path.resolve(compiler.outputPath, '..', 'build', 'Release');
91
+ if (process.platform === 'win32') {
92
+ const agentFile = require.resolve('node-pty/build/Release/winpty-agent.exe');
93
+ const targetAgentFile = path.join(targetDirectory, 'winpty-agent.exe');
94
+ await this.copyExecutable(agentFile, targetAgentFile);
95
+ const dllFile = require.resolve('node-pty/build/Release/winpty.dll');
96
+ const targetDllFile = path.join(targetDirectory, 'winpty.dll');
97
+ await this.copyExecutable(dllFile, targetDllFile);
98
+ }
99
+ else {
100
+ const sourceFile = require.resolve('node-pty/build/Release/spawn-helper');
101
+ const targetFile = path.join(targetDirectory, 'spawn-helper');
102
+ await this.copyExecutable(sourceFile, targetFile);
103
+ }
104
+ }
105
+ async copyExecutable(source, target) {
106
+ const targetDirectory = path.dirname(target);
107
+ await fs.promises.mkdir(targetDirectory, { recursive: true });
108
+ await fs.promises.copyFile(source, target);
109
+ await fs.promises.chmod(target, 0o777);
110
+ }
111
+ }
112
+ exports.NativeWebpackPlugin = NativeWebpackPlugin;
113
+ function buildFile(root, name, content) {
114
+ const tmpFile = path.join(root, name);
115
+ fs.writeFileSync(tmpFile, content);
116
+ return tmpFile;
117
+ }
118
+ const ripgrepReplacement = (nativePath = '.') => `
119
+ const path = require('path');
120
+
121
+ exports.rgPath = path.join(__dirname, \`./${nativePath}/rg\${process.platform === 'win32' ? '.exe' : ''}\`);
122
+ `;
123
+ const bindingsReplacement = (entries) => {
124
+ const cases = [];
125
+ for (const [module, node] of entries) {
126
+ cases.push(`${' '.repeat(8)}case '${module}': return require('${node}');`);
127
+ }
128
+ return `
129
+ module.exports = function (jsModule) {
130
+ switch (jsModule) {
131
+ ${cases.join(os.EOL)}
132
+ }
133
+ throw new Error(\`unhandled module: "\${jsModule}"\`);
134
+ }`.trim();
135
+ };
136
+ //# sourceMappingURL=native-webpack-plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"native-webpack-plugin.js","sourceRoot":"","sources":["../src/native-webpack-plugin.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,yCAAyC;AACzC,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;;;AAEhF,6BAA6B;AAC7B,yBAAyB;AACzB,yBAAyB;AACzB,6BAA6B;AAI7B,MAAM,eAAe,GAAG,iBAAiB,CAAC;AAC1C,MAAM,+BAA+B,GAAG,0BAA0B,CAAC;AACnE,MAAM,gBAAgB,GAAG,UAAU,CAAC;AACpC,M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AAG,EAAU,EAAE,CAAC;;;4CAGrB,UAAU;CACrD,CAAC;AAEF,MAAM,mBAAmB,GAAG,CAAC,OAA2B,EAAU,EAAE;IAChE,MAAM,KAAK,GAAa,EAAE,CAAC;IAE3B,KAAK,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,OAAO,EAAE;QAClC,KAAK,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,MAAM,sBAAsB,IAAI,KAAK,CAAC,CAAC;KAC9E;IAED,OAAO;;;EAGT,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC;;;EAGlB,CAAC,IAAI,EAAE,CAAC;AACV,CAAC,CAAC"}
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=package.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"package.spec.d.ts","sourceRoot":"","sources":["../src/package.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +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
+ });
26
+ //# sourceMappingURL=package.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"package.spec.js","sourceRoot":"","sources":["../src/package.spec.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,yCAAyC;AACzC,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;AAEhF;;;;;;qBAMqB;AAErB,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAE7B,EAAE,CAAC,yCAAyC,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC;AAC9D,CAAC,CAAC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@theia/native-webpack-plugin",
3
+ "version": "1.39.0-next.19+72e48cc2d",
4
+ "description": "Webpack Plugin for native dependencies of Theia.",
5
+ "publishConfig": {
6
+ "access": "public"
7
+ },
8
+ "license": "EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/eclipse-theia/theia.git"
12
+ },
13
+ "bugs": {
14
+ "url": "https://github.com/eclipse-theia/theia/issues"
15
+ },
16
+ "homepage": "https://github.com/eclipse-theia/theia",
17
+ "files": [
18
+ "lib",
19
+ "src"
20
+ ],
21
+ "main": "lib/index.js",
22
+ "typings": "lib/index.d.ts",
23
+ "scripts": {
24
+ "build": "theiaext build",
25
+ "clean": "theiaext clean",
26
+ "compile": "theiaext compile",
27
+ "lint": "theiaext lint",
28
+ "test": "theiaext test",
29
+ "watch": "theiaext watch"
30
+ },
31
+ "dependencies": {
32
+ "temp": "^0.9.1",
33
+ "webpack": "^5.76.0"
34
+ },
35
+ "gitHead": "72e48cc2d4d5cad62b9ae7ef76775da9711da560"
36
+ }
package/src/index.ts ADDED
@@ -0,0 +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;
@@ -0,0 +1,164 @@
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
+ import * as temp from 'temp';
21
+
22
+ import type { Compiler } from 'webpack';
23
+
24
+ const REQUIRE_RIPGREP = '@vscode/ripgrep';
25
+ const REQUIRE_VSCODE_WINDOWS_CA_CERTS = '@vscode/windows-ca-certs';
26
+ const REQUIRE_BINDINGS = 'bindings';
27
+ const REQUIRE_KEYMAPPING = './build/Release/keymapping';
28
+
29
+ export interface NativeWebpackPluginOptions {
30
+ out: string;
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
+ private tracker: typeof temp;
42
+
43
+ constructor(options: NativeWebpackPluginOptions) {
44
+ this.options = options;
45
+ this.tracker = temp.track();
46
+ for (const [name, value] of Object.entries(options.nativeBindings ?? {})) {
47
+ this.nativeBinding(name, value);
48
+ }
49
+ }
50
+
51
+ nativeBinding(dependency: string, nodePath: string): void {
52
+ this.bindings.set(dependency, nodePath);
53
+ }
54
+
55
+ apply(compiler: Compiler): void {
56
+ let replacements: Record<string, string> = {};
57
+ compiler.hooks.initialize.tap(NativeWebpackPlugin.name, () => {
58
+ const directory = this.tracker.mkdirSync({
59
+ dir: path.resolve(compiler.outputPath, 'native-webpack-plugin')
60
+ });
61
+ const bindingsFile = buildFile(directory, 'bindings.js', bindingsReplacement(Array.from(this.bindings.entries())));
62
+ const ripgrepFile = buildFile(directory, 'ripgrep.js', ripgrepReplacement(this.options.out));
63
+ const keymappingFile = './build/Release/keymapping.node';
64
+ const windowsCaCertsFile = '@vscode/windows-ca-certs/build/Release/crypt32.node';
65
+ replacements = {
66
+ ...(this.options.replacements ?? {}),
67
+ [REQUIRE_RIPGREP]: ripgrepFile,
68
+ [REQUIRE_BINDINGS]: bindingsFile,
69
+ [REQUIRE_KEYMAPPING]: keymappingFile,
70
+ [REQUIRE_VSCODE_WINDOWS_CA_CERTS]: windowsCaCertsFile
71
+ };
72
+ });
73
+ compiler.hooks.normalModuleFactory.tap(
74
+ NativeWebpackPlugin.name,
75
+ nmf => {
76
+ nmf.hooks.beforeResolve.tap(NativeWebpackPlugin.name, result => {
77
+ for (const [file, replacement] of Object.entries(replacements)) {
78
+ if (result.request === file) {
79
+ result.request = replacement;
80
+ }
81
+ }
82
+ });
83
+ nmf.hooks.afterResolve.tap(NativeWebpackPlugin.name, result => {
84
+ const createData = result.createData;
85
+ for (const [file, replacement] of Object.entries(replacements)) {
86
+ if (createData.resource === file) {
87
+ createData.resource = replacement;
88
+ }
89
+ }
90
+ });
91
+ }
92
+ );
93
+ compiler.hooks.afterEmit.tapAsync(NativeWebpackPlugin.name, async () => {
94
+ if (this.options.ripgrep) {
95
+ await this.copyRipgrep(compiler);
96
+ }
97
+ if (this.options.pty) {
98
+ await this.copyNodePtySpawnHelper(compiler);
99
+ }
100
+ this.tracker.cleanupSync();
101
+ });
102
+ compiler.hooks.failed.tap(NativeWebpackPlugin.name, async () => {
103
+ this.tracker.cleanupSync();
104
+ });
105
+ }
106
+
107
+ protected async copyRipgrep(compiler: Compiler): Promise<void> {
108
+ const suffix = process.platform === 'win32' ? '.exe' : '';
109
+ const sourceFile = require.resolve(`@vscode/ripgrep/bin/rg${suffix}`);
110
+ const targetFile = path.join(compiler.outputPath, this.options.out, `rg${suffix}`);
111
+ await this.copyExecutable(sourceFile, targetFile);
112
+ }
113
+
114
+ protected async copyNodePtySpawnHelper(compiler: Compiler): Promise<void> {
115
+ const targetDirectory = path.resolve(compiler.outputPath, '..', 'build', 'Release');
116
+ if (process.platform === 'win32') {
117
+ const agentFile = require.resolve('node-pty/build/Release/winpty-agent.exe');
118
+ const targetAgentFile = path.join(targetDirectory, 'winpty-agent.exe');
119
+ await this.copyExecutable(agentFile, targetAgentFile);
120
+ const dllFile = require.resolve('node-pty/build/Release/winpty.dll');
121
+ const targetDllFile = path.join(targetDirectory, 'winpty.dll');
122
+ await this.copyExecutable(dllFile, targetDllFile);
123
+ } else {
124
+ const sourceFile = require.resolve('node-pty/build/Release/spawn-helper');
125
+ const targetFile = path.join(targetDirectory, 'spawn-helper');
126
+ await this.copyExecutable(sourceFile, targetFile);
127
+ }
128
+ }
129
+
130
+ protected async copyExecutable(source: string, target: string): Promise<void> {
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
+
138
+ function buildFile(root: string, name: string, content: string): string {
139
+ const tmpFile = path.join(root, name);
140
+ fs.writeFileSync(tmpFile, content);
141
+ return tmpFile;
142
+ }
143
+
144
+ const ripgrepReplacement = (nativePath: string = '.'): string => `
145
+ const path = require('path');
146
+
147
+ exports.rgPath = path.join(__dirname, \`./${nativePath}/rg\${process.platform === 'win32' ? '.exe' : ''}\`);
148
+ `;
149
+
150
+ const bindingsReplacement = (entries: [string, string][]): string => {
151
+ const cases: string[] = [];
152
+
153
+ for (const [module, node] of entries) {
154
+ cases.push(`${' '.repeat(8)}case '${module}': return require('${node}');`);
155
+ }
156
+
157
+ return `
158
+ module.exports = function (jsModule) {
159
+ switch (jsModule) {
160
+ ${cases.join(os.EOL)}
161
+ }
162
+ throw new Error(\`unhandled module: "\${jsModule}"\`);
163
+ }`.trim();
164
+ };
@@ -0,0 +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
+ });