Socket
Socket
Sign inDemoInstall

@esbuild-plugins/node-globals-polyfill

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@esbuild-plugins/node-globals-polyfill - npm Package Compare versions

Comparing version 0.1.1 to 0.2.0

3

dist/index.d.ts
import * as esbuild from 'esbuild';
export declare function NodeGlobalsPolyfillPlugin({ buffer, define, process, }?: {
export declare function NodeGlobalsPolyfillPlugin({ buffer, process, }?: {
buffer?: boolean | undefined;
define?: {} | undefined;
process?: boolean | undefined;

@@ -6,0 +5,0 @@ }): esbuild.Plugin;

@@ -8,4 +8,5 @@ "use strict";

const path_1 = __importDefault(require("path"));
const fs_1 = __importDefault(require("fs"));
function NodeGlobalsPolyfillPlugin({ buffer = false, define = {}, process = true, } = {}) {
function NodeGlobalsPolyfillPlugin({ buffer = false,
// define = {},
process = true, } = {}) {
return {

@@ -24,16 +25,31 @@ name: 'node-globals-polyfill',

});
onLoad({ filter: /_virtual-process-polyfill_\.js/ }, (arg) => {
const data = fs_1.default
.readFileSync(path_1.default.resolve(__dirname, '../process.js'))
.toString();
const keys = Object.keys(define);
// TODO esbuild cannot use virtual modules for inject: https://github.com/evanw/esbuild/issues/2762
// onLoad({ filter: /_virtual-process-polyfill_\.js/ }, (arg) => {
// const data = fs
// .readFileSync(path.resolve(__dirname, '../process.js'))
// .toString()
// const keys = Object.keys(define)
// return {
// loader: 'js',
// contents: data.replace(
// `const defines = {}`,
// 'const defines = {\n' +
// keys
// .filter((x) => x.startsWith('process.'))
// .sort((a, b) => a.length - b.length)
// .map(
// (k) =>
// ` ${JSON.stringify(k).replace(
// 'process.',
// '',
// )}: ${define[k]},`,
// )
// .join('\n') +
// '\n}',
// ),
// }
// })
onResolve({ filter: /_virtual-process-polyfill_\.js/ }, () => {
return {
loader: 'js',
contents: data.replace(`const defines = {}`, 'const defines = {\n' +
keys
.filter((x) => x.startsWith('process.'))
.sort((a, b) => a.length - b.length)
.map((k) => ` ${JSON.stringify(k).replace('process.', '')}: ${define[k]},`)
.join('\n') +
'\n}'),
path: path_1.default.resolve(__dirname, '../process.js'),
};

@@ -40,0 +56,0 @@ });

@@ -49,2 +49,3 @@ "use strict";

}));
// TODO esbuild cannot use virtual modules for inject: https://github.com/evanw/esbuild/issues/2762
test('process env vars are replaced with ones from define', () => __awaiter(void 0, void 0, void 0, function* () {

@@ -60,9 +61,6 @@ const { unlink, paths: [ENTRY], } = yield test_support_1.writeFiles({

bundle: true,
plugins: [
_1.NodeGlobalsPolyfillPlugin({
define: {
'process.env.VAR': '"hello"',
},
}),
],
define: {
'process.env.VAR': '"hello"',
},
plugins: [_1.NodeGlobalsPolyfillPlugin({})],
});

@@ -69,0 +67,0 @@ const output = res.outputFiles[0].text;

import * as esbuild from 'esbuild';
export declare function NodeGlobalsPolyfillPlugin({ buffer, define, process, }?: {
export declare function NodeGlobalsPolyfillPlugin({ buffer, process, }?: {
buffer?: boolean | undefined;
define?: {} | undefined;
process?: boolean | undefined;

@@ -6,0 +5,0 @@ }): esbuild.Plugin;

import path from 'path';
import fs from 'fs';
export function NodeGlobalsPolyfillPlugin({ buffer = false, define = {}, process = true, } = {}) {
export function NodeGlobalsPolyfillPlugin({ buffer = false,
// define = {},
process = true, } = {}) {
return {

@@ -17,16 +18,31 @@ name: 'node-globals-polyfill',

});
onLoad({ filter: /_virtual-process-polyfill_\.js/ }, (arg) => {
const data = fs
.readFileSync(path.resolve(__dirname, '../process.js'))
.toString();
const keys = Object.keys(define);
// TODO esbuild cannot use virtual modules for inject: https://github.com/evanw/esbuild/issues/2762
// onLoad({ filter: /_virtual-process-polyfill_\.js/ }, (arg) => {
// const data = fs
// .readFileSync(path.resolve(__dirname, '../process.js'))
// .toString()
// const keys = Object.keys(define)
// return {
// loader: 'js',
// contents: data.replace(
// `const defines = {}`,
// 'const defines = {\n' +
// keys
// .filter((x) => x.startsWith('process.'))
// .sort((a, b) => a.length - b.length)
// .map(
// (k) =>
// ` ${JSON.stringify(k).replace(
// 'process.',
// '',
// )}: ${define[k]},`,
// )
// .join('\n') +
// '\n}',
// ),
// }
// })
onResolve({ filter: /_virtual-process-polyfill_\.js/ }, () => {
return {
loader: 'js',
contents: data.replace(`const defines = {}`, 'const defines = {\n' +
keys
.filter((x) => x.startsWith('process.'))
.sort((a, b) => a.length - b.length)
.map((k) => ` ${JSON.stringify(k).replace('process.', '')}: ${define[k]},`)
.join('\n') +
'\n}'),
path: path.resolve(__dirname, '../process.js'),
};

@@ -33,0 +49,0 @@ });

@@ -47,2 +47,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

}));
// TODO esbuild cannot use virtual modules for inject: https://github.com/evanw/esbuild/issues/2762
test('process env vars are replaced with ones from define', () => __awaiter(void 0, void 0, void 0, function* () {

@@ -58,9 +59,6 @@ const { unlink, paths: [ENTRY], } = yield writeFiles({

bundle: true,
plugins: [
NodeGlobalsPolyfillPlugin({
define: {
'process.env.VAR': '"hello"',
},
}),
],
define: {
'process.env.VAR': '"hello"',
},
plugins: [NodeGlobalsPolyfillPlugin({})],
});

@@ -67,0 +65,0 @@ const output = res.outputFiles[0].text;

{
"name": "@esbuild-plugins/node-globals-polyfill",
"version": "0.1.1",
"version": "0.2.0",
"description": "",

@@ -5,0 +5,0 @@ "preferUnplugged": true,

@@ -47,2 +47,4 @@ import { build } from 'esbuild'

})
// TODO esbuild cannot use virtual modules for inject: https://github.com/evanw/esbuild/issues/2762
test('process env vars are replaced with ones from define', async () => {

@@ -61,9 +63,6 @@ const {

bundle: true,
plugins: [
NodeGlobalsPolyfillPlugin({
define: {
'process.env.VAR': '"hello"',
},
}),
],
define: {
'process.env.VAR': '"hello"',
},
plugins: [NodeGlobalsPolyfillPlugin({})],
})

@@ -70,0 +69,0 @@ const output = res.outputFiles[0].text

@@ -7,3 +7,3 @@ import path from 'path'

buffer = false,
define = {},
// define = {},
process = true,

@@ -25,26 +25,32 @@ } = {}): esbuild.Plugin {

onLoad({ filter: /_virtual-process-polyfill_\.js/ }, (arg) => {
const data = fs
.readFileSync(path.resolve(__dirname, '../process.js'))
.toString()
// TODO esbuild cannot use virtual modules for inject: https://github.com/evanw/esbuild/issues/2762
// onLoad({ filter: /_virtual-process-polyfill_\.js/ }, (arg) => {
// const data = fs
// .readFileSync(path.resolve(__dirname, '../process.js'))
// .toString()
const keys = Object.keys(define)
// const keys = Object.keys(define)
// return {
// loader: 'js',
// contents: data.replace(
// `const defines = {}`,
// 'const defines = {\n' +
// keys
// .filter((x) => x.startsWith('process.'))
// .sort((a, b) => a.length - b.length)
// .map(
// (k) =>
// ` ${JSON.stringify(k).replace(
// 'process.',
// '',
// )}: ${define[k]},`,
// )
// .join('\n') +
// '\n}',
// ),
// }
// })
onResolve({ filter: /_virtual-process-polyfill_\.js/ }, () => {
return {
loader: 'js',
contents: data.replace(
`const defines = {}`,
'const defines = {\n' +
keys
.filter((x) => x.startsWith('process.'))
.sort((a, b) => a.length - b.length)
.map(
(k) =>
` ${JSON.stringify(k).replace(
'process.',
'',
)}: ${define[k]},`,
)
.join('\n') +
'\n}',
),
path: path.resolve(__dirname, '../process.js'),
}

@@ -51,0 +57,0 @@ })

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc