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.0 to 0.1.1

4

Buffer.js

@@ -1072,5 +1072,5 @@ // taken from https://github.com/calvinmetcalf/buffer-es6

if (start === 0 && end === buf.length) {
return fromByteArray(buf)
return base64fromByteArray(buf)
} else {
return fromByteArray(buf.slice(start, end))
return base64fromByteArray(buf.slice(start, end))
}

@@ -1077,0 +1077,0 @@ }

# @esbuild-plugins/node-globals-polyfill
## 0.1.1
### Patch Changes
- Fix base64fromByteArray call on Buffer.js
## 0.1.0

@@ -4,0 +10,0 @@

"use strict";
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
var __spread = (this && this.__spread) || function () {
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
return ar;
};
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -27,12 +7,9 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

exports.NodeGlobalsPolyfillPlugin = void 0;
var path_1 = __importDefault(require("path"));
var fs_1 = __importDefault(require("fs"));
function NodeGlobalsPolyfillPlugin(_a) {
var _b = _a === void 0 ? {} : _a, _c = _b.buffer, buffer = _c === void 0 ? false : _c, _d = _b.define, define = _d === void 0 ? {} : _d, _e = _b.process, process = _e === void 0 ? true : _e;
const path_1 = __importDefault(require("path"));
const fs_1 = __importDefault(require("fs"));
function NodeGlobalsPolyfillPlugin({ buffer = false, define = {}, process = true, } = {}) {
return {
name: 'node-globals-polyfill',
setup: function (_a) {
var _b;
var initialOptions = _a.initialOptions, onResolve = _a.onResolve, onLoad = _a.onLoad;
onResolve({ filter: /_node-buffer-polyfill_\.js/ }, function (arg) {
setup({ initialOptions, onResolve, onLoad }) {
onResolve({ filter: /_node-buffer-polyfill_\.js/ }, (arg) => {
return {

@@ -42,3 +19,3 @@ path: path_1.default.resolve(__dirname, '../Buffer.js'),

});
onResolve({ filter: /_node-process-polyfill_\.js/ }, function (arg) {
onResolve({ filter: /_node-process-polyfill_\.js/ }, (arg) => {
return {

@@ -48,16 +25,14 @@ path: path_1.default.resolve(__dirname, '../process.js'),

});
onLoad({ filter: /_virtual-process-polyfill_\.js/ }, function (arg) {
var data = fs_1.default
onLoad({ filter: /_virtual-process-polyfill_\.js/ }, (arg) => {
const data = fs_1.default
.readFileSync(path_1.default.resolve(__dirname, '../process.js'))
.toString();
var keys = Object.keys(define);
const keys = Object.keys(define);
return {
loader: 'js',
contents: data.replace("const defines = {}", 'const defines = {\n' +
contents: data.replace(`const defines = {}`, 'const defines = {\n' +
keys
.filter(function (x) { return x.startsWith('process.'); })
.sort(function (a, b) { return a.length - b.length; })
.map(function (k) {
return " " + JSON.stringify(k).replace('process.', '') + ": " + define[k] + ",";
})
.filter((x) => x.startsWith('process.'))
.sort((a, b) => a.length - b.length)
.map((k) => ` ${JSON.stringify(k).replace('process.', '')}: ${define[k]},`)
.join('\n') +

@@ -67,3 +42,3 @@ '\n}'),

});
var polyfills = [];
const polyfills = [];
if (process) {

@@ -76,6 +51,6 @@ polyfills.push(path_1.default.resolve(__dirname, '../_virtual-process-polyfill_.js'));

if (initialOptions.inject) {
(_b = initialOptions.inject).push.apply(_b, __spread(polyfills));
initialOptions.inject.push(...polyfills);
}
else {
initialOptions.inject = __spread(polyfills);
initialOptions.inject = [...polyfills];
}

@@ -82,0 +57,0 @@ },

@@ -11,242 +11,132 @@ "use strict";

};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
Object.defineProperty(exports, "__esModule", { value: true });
var esbuild_1 = require("esbuild");
var test_support_1 = require("test-support");
var _1 = require(".");
const esbuild_1 = require("esbuild");
const test_support_1 = require("test-support");
const _1 = require(".");
require('debug').enable(require('../package.json').name);
test('process works', function () { return __awaiter(void 0, void 0, void 0, function () {
var _a, unlink, _b, ENTRY, res, output;
return __generator(this, function (_c) {
switch (_c.label) {
case 0: return [4 /*yield*/, test_support_1.writeFiles({
'entry.ts': "process.version",
})];
case 1:
_a = _c.sent(), unlink = _a.unlink, _b = __read(_a.paths, 1), ENTRY = _b[0];
return [4 /*yield*/, esbuild_1.build({
entryPoints: [ENTRY],
write: false,
format: 'esm',
target: 'es2017',
bundle: true,
inject: [require.resolve('../process')],
})];
case 2:
res = _c.sent();
output = res.outputFiles[0].text;
// console.log(output)
eval(output);
unlink();
return [2 /*return*/];
}
test('process works', () => __awaiter(void 0, void 0, void 0, function* () {
const { unlink, paths: [ENTRY], } = yield test_support_1.writeFiles({
'entry.ts': `process.version`,
});
}); });
test('process is tree shaken', function () { return __awaiter(void 0, void 0, void 0, function () {
var _a, unlink, _b, ENTRY, res, output;
return __generator(this, function (_c) {
switch (_c.label) {
case 0: return [4 /*yield*/, test_support_1.writeFiles({
'entry.ts': "console.log('hei')",
})];
case 1:
_a = _c.sent(), unlink = _a.unlink, _b = __read(_a.paths, 1), ENTRY = _b[0];
return [4 /*yield*/, esbuild_1.build({
entryPoints: [ENTRY],
write: false,
format: 'esm',
target: 'es2017',
bundle: true,
inject: [require.resolve('../process')],
})];
case 2:
res = _c.sent();
output = res.outputFiles[0].text;
expect(output).not.toContain('process');
unlink();
return [2 /*return*/];
}
const res = yield esbuild_1.build({
entryPoints: [ENTRY],
write: false,
format: 'esm',
target: 'es2017',
bundle: true,
inject: [require.resolve('../process')],
});
}); });
test('process env vars are replaced with ones from define', function () { return __awaiter(void 0, void 0, void 0, function () {
var _a, unlink, _b, ENTRY, res, output;
return __generator(this, function (_c) {
switch (_c.label) {
case 0: return [4 /*yield*/, test_support_1.writeFiles({
'entry.ts': "if (process.env.VAR !== 'hello') { throw new Error('process.env.VAR not right: ' + process.env.VAR) }",
})];
case 1:
_a = _c.sent(), unlink = _a.unlink, _b = __read(_a.paths, 1), ENTRY = _b[0];
return [4 /*yield*/, esbuild_1.build({
entryPoints: [ENTRY],
write: false,
format: 'esm',
target: 'es2017',
bundle: true,
plugins: [
_1.NodeGlobalsPolyfillPlugin({
define: {
'process.env.VAR': '"hello"',
},
}),
],
})];
case 2:
res = _c.sent();
output = res.outputFiles[0].text;
eval(output);
unlink();
return [2 /*return*/];
}
const output = res.outputFiles[0].text;
// console.log(output)
eval(output);
unlink();
}));
test('process is tree shaken', () => __awaiter(void 0, void 0, void 0, function* () {
const { unlink, paths: [ENTRY], } = yield test_support_1.writeFiles({
'entry.ts': `console.log('hei')`,
});
}); });
test('Buffer works', function () { return __awaiter(void 0, void 0, void 0, function () {
var _a, unlink, _b, ENTRY, res, output;
return __generator(this, function (_c) {
switch (_c.label) {
case 0: return [4 /*yield*/, test_support_1.writeFiles({
'entry.ts': "console.log(Buffer.from('xxx').toString())",
})];
case 1:
_a = _c.sent(), unlink = _a.unlink, _b = __read(_a.paths, 1), ENTRY = _b[0];
return [4 /*yield*/, esbuild_1.build({
entryPoints: [ENTRY],
write: false,
format: 'esm',
target: 'es2017',
bundle: true,
inject: [require.resolve('../Buffer')],
})];
case 2:
res = _c.sent();
output = res.outputFiles[0].text;
// console.log(output)
eval(output);
unlink();
return [2 /*return*/];
}
const res = yield esbuild_1.build({
entryPoints: [ENTRY],
write: false,
format: 'esm',
target: 'es2017',
bundle: true,
inject: [require.resolve('../process')],
});
}); });
test('Buffer is tree shaken', function () { return __awaiter(void 0, void 0, void 0, function () {
var _a, unlink, _b, ENTRY, res, output;
return __generator(this, function (_c) {
switch (_c.label) {
case 0: return [4 /*yield*/, test_support_1.writeFiles({
'entry.ts': "console.log('hei')",
})];
case 1:
_a = _c.sent(), unlink = _a.unlink, _b = __read(_a.paths, 1), ENTRY = _b[0];
return [4 /*yield*/, esbuild_1.build({
entryPoints: [ENTRY],
write: false,
format: 'esm',
target: 'es2017',
bundle: true,
inject: [require.resolve('../Buffer')],
})];
case 2:
res = _c.sent();
output = res.outputFiles[0].text;
expect(output).not.toContain('Buffer');
unlink();
return [2 /*return*/];
}
const output = res.outputFiles[0].text;
expect(output).not.toContain('process');
unlink();
}));
test('process env vars are replaced with ones from define', () => __awaiter(void 0, void 0, void 0, function* () {
const { unlink, paths: [ENTRY], } = yield test_support_1.writeFiles({
'entry.ts': `if (process.env.VAR !== 'hello') { throw new Error('process.env.VAR not right: ' + process.env.VAR) }`,
});
}); });
test('Buffer works using plugin', function () { return __awaiter(void 0, void 0, void 0, function () {
var _a, unlink, _b, ENTRY, res, output;
return __generator(this, function (_c) {
switch (_c.label) {
case 0: return [4 /*yield*/, test_support_1.writeFiles({
'entry.ts': "\n let buf = new Buffer(256);\n let len = buf.write(\"Simply Easy Learning\");\n console.log(\"Octets written : \"+ len);",
})];
case 1:
_a = _c.sent(), unlink = _a.unlink, _b = __read(_a.paths, 1), ENTRY = _b[0];
return [4 /*yield*/, esbuild_1.build({
entryPoints: [ENTRY],
write: false,
format: 'esm',
target: 'es2017',
bundle: true,
plugins: [_1.NodeGlobalsPolyfillPlugin({ buffer: true })],
})];
case 2:
res = _c.sent();
output = res.outputFiles[0].text;
// console.log(output)
eval(output);
unlink();
return [2 /*return*/];
}
const res = yield esbuild_1.build({
entryPoints: [ENTRY],
write: false,
format: 'esm',
target: 'es2017',
bundle: true,
plugins: [
_1.NodeGlobalsPolyfillPlugin({
define: {
'process.env.VAR': '"hello"',
},
}),
],
});
}); });
test('process works using plugin', function () { return __awaiter(void 0, void 0, void 0, function () {
var _a, unlink, _b, ENTRY, res, output;
return __generator(this, function (_c) {
switch (_c.label) {
case 0: return [4 /*yield*/, test_support_1.writeFiles({
'entry.ts': "console.log(process.cwd())",
})];
case 1:
_a = _c.sent(), unlink = _a.unlink, _b = __read(_a.paths, 1), ENTRY = _b[0];
return [4 /*yield*/, esbuild_1.build({
entryPoints: [ENTRY],
write: false,
format: 'esm',
target: 'es2017',
bundle: true,
plugins: [_1.NodeGlobalsPolyfillPlugin({ process: true })],
})];
case 2:
res = _c.sent();
output = res.outputFiles[0].text;
// console.log(output)
eval(output);
unlink();
return [2 /*return*/];
}
const output = res.outputFiles[0].text;
eval(output);
unlink();
}));
test('Buffer works', () => __awaiter(void 0, void 0, void 0, function* () {
const { unlink, paths: [ENTRY], } = yield test_support_1.writeFiles({
'entry.ts': `console.log(Buffer.from('xxx').toString())`,
});
}); });
const res = yield esbuild_1.build({
entryPoints: [ENTRY],
write: false,
format: 'esm',
target: 'es2017',
bundle: true,
inject: [require.resolve('../Buffer')],
});
const output = res.outputFiles[0].text;
// console.log(output)
eval(output);
unlink();
}));
test('Buffer is tree shaken', () => __awaiter(void 0, void 0, void 0, function* () {
const { unlink, paths: [ENTRY], } = yield test_support_1.writeFiles({
'entry.ts': `console.log('hei')`,
});
const res = yield esbuild_1.build({
entryPoints: [ENTRY],
write: false,
format: 'esm',
target: 'es2017',
bundle: true,
inject: [require.resolve('../Buffer')],
});
const output = res.outputFiles[0].text;
expect(output).not.toContain('Buffer');
unlink();
}));
test('Buffer works using plugin', () => __awaiter(void 0, void 0, void 0, function* () {
const { unlink, paths: [ENTRY], } = yield test_support_1.writeFiles({
'entry.ts': `
let buf = new Buffer(256);
let len = buf.write("Simply Easy Learning");
console.log("Octets written : "+ len);`,
});
const res = yield esbuild_1.build({
entryPoints: [ENTRY],
write: false,
format: 'esm',
target: 'es2017',
bundle: true,
plugins: [_1.NodeGlobalsPolyfillPlugin({ buffer: true })],
});
const output = res.outputFiles[0].text;
// console.log(output)
eval(output);
unlink();
}));
test('process works using plugin', () => __awaiter(void 0, void 0, void 0, function* () {
const { unlink, paths: [ENTRY], } = yield test_support_1.writeFiles({
'entry.ts': `console.log(process.cwd())`,
});
const res = yield esbuild_1.build({
entryPoints: [ENTRY],
write: false,
format: 'esm',
target: 'es2017',
bundle: true,
plugins: [_1.NodeGlobalsPolyfillPlugin({ process: true })],
});
const output = res.outputFiles[0].text;
// console.log(output)
eval(output);
unlink();
}));
//# sourceMappingURL=index.test.js.map

@@ -1,2 +0,8 @@

export {};
import * as esbuild from 'esbuild';
export declare function NodeGlobalsPolyfillPlugin({ buffer, define, process, }?: {
buffer?: boolean | undefined;
define?: {} | undefined;
process?: boolean | undefined;
}): esbuild.Plugin;
export default NodeGlobalsPolyfillPlugin;
//# sourceMappingURL=index.d.ts.map

@@ -1,2 +0,50 @@

export {};
import path from 'path';
import fs from 'fs';
export function NodeGlobalsPolyfillPlugin({ buffer = false, define = {}, process = true, } = {}) {
return {
name: 'node-globals-polyfill',
setup({ initialOptions, onResolve, onLoad }) {
onResolve({ filter: /_node-buffer-polyfill_\.js/ }, (arg) => {
return {
path: path.resolve(__dirname, '../Buffer.js'),
};
});
onResolve({ filter: /_node-process-polyfill_\.js/ }, (arg) => {
return {
path: path.resolve(__dirname, '../process.js'),
};
});
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}'),
};
});
const polyfills = [];
if (process) {
polyfills.push(path.resolve(__dirname, '../_virtual-process-polyfill_.js'));
}
if (buffer) {
polyfills.push(path.resolve(__dirname, '../_buffer.js'));
}
if (initialOptions.inject) {
initialOptions.inject.push(...polyfills);
}
else {
initialOptions.inject = [...polyfills];
}
},
};
}
export default NodeGlobalsPolyfillPlugin;
//# sourceMappingURL=index.js.map

@@ -10,75 +10,131 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
import { build } from 'esbuild';
import { writeFiles } from 'test-support';
import { NodeGlobalsPolyfillPlugin } from '.';
require('debug').enable(require('../package.json').name);
test('works', function () { return __awaiter(void 0, void 0, void 0, function () {
var _a, unlink, _b, ENTRY, res, output;
return __generator(this, function (_c) {
switch (_c.label) {
case 0: return [4 /*yield*/, writeFiles({
'entry.ts': "process.version",
})];
case 1:
_a = _c.sent(), unlink = _a.unlink, _b = __read(_a.paths, 1), ENTRY = _b[0];
return [4 /*yield*/, build({
entryPoints: [ENTRY],
write: false,
format: 'esm',
target: 'es2017',
bundle: true,
inject: [require.resolve('../process')],
})];
case 2:
res = _c.sent();
output = res.outputFiles[0].text;
// console.log(output)
eval(output);
unlink();
return [2 /*return*/];
}
test('process works', () => __awaiter(void 0, void 0, void 0, function* () {
const { unlink, paths: [ENTRY], } = yield writeFiles({
'entry.ts': `process.version`,
});
}); });
const res = yield build({
entryPoints: [ENTRY],
write: false,
format: 'esm',
target: 'es2017',
bundle: true,
inject: [require.resolve('../process')],
});
const output = res.outputFiles[0].text;
// console.log(output)
eval(output);
unlink();
}));
test('process is tree shaken', () => __awaiter(void 0, void 0, void 0, function* () {
const { unlink, paths: [ENTRY], } = yield writeFiles({
'entry.ts': `console.log('hei')`,
});
const res = yield build({
entryPoints: [ENTRY],
write: false,
format: 'esm',
target: 'es2017',
bundle: true,
inject: [require.resolve('../process')],
});
const output = res.outputFiles[0].text;
expect(output).not.toContain('process');
unlink();
}));
test('process env vars are replaced with ones from define', () => __awaiter(void 0, void 0, void 0, function* () {
const { unlink, paths: [ENTRY], } = yield writeFiles({
'entry.ts': `if (process.env.VAR !== 'hello') { throw new Error('process.env.VAR not right: ' + process.env.VAR) }`,
});
const res = yield build({
entryPoints: [ENTRY],
write: false,
format: 'esm',
target: 'es2017',
bundle: true,
plugins: [
NodeGlobalsPolyfillPlugin({
define: {
'process.env.VAR': '"hello"',
},
}),
],
});
const output = res.outputFiles[0].text;
eval(output);
unlink();
}));
test('Buffer works', () => __awaiter(void 0, void 0, void 0, function* () {
const { unlink, paths: [ENTRY], } = yield writeFiles({
'entry.ts': `console.log(Buffer.from('xxx').toString())`,
});
const res = yield build({
entryPoints: [ENTRY],
write: false,
format: 'esm',
target: 'es2017',
bundle: true,
inject: [require.resolve('../Buffer')],
});
const output = res.outputFiles[0].text;
// console.log(output)
eval(output);
unlink();
}));
test('Buffer is tree shaken', () => __awaiter(void 0, void 0, void 0, function* () {
const { unlink, paths: [ENTRY], } = yield writeFiles({
'entry.ts': `console.log('hei')`,
});
const res = yield build({
entryPoints: [ENTRY],
write: false,
format: 'esm',
target: 'es2017',
bundle: true,
inject: [require.resolve('../Buffer')],
});
const output = res.outputFiles[0].text;
expect(output).not.toContain('Buffer');
unlink();
}));
test('Buffer works using plugin', () => __awaiter(void 0, void 0, void 0, function* () {
const { unlink, paths: [ENTRY], } = yield writeFiles({
'entry.ts': `
let buf = new Buffer(256);
let len = buf.write("Simply Easy Learning");
console.log("Octets written : "+ len);`,
});
const res = yield build({
entryPoints: [ENTRY],
write: false,
format: 'esm',
target: 'es2017',
bundle: true,
plugins: [NodeGlobalsPolyfillPlugin({ buffer: true })],
});
const output = res.outputFiles[0].text;
// console.log(output)
eval(output);
unlink();
}));
test('process works using plugin', () => __awaiter(void 0, void 0, void 0, function* () {
const { unlink, paths: [ENTRY], } = yield writeFiles({
'entry.ts': `console.log(process.cwd())`,
});
const res = yield build({
entryPoints: [ENTRY],
write: false,
format: 'esm',
target: 'es2017',
bundle: true,
plugins: [NodeGlobalsPolyfillPlugin({ process: true })],
});
const output = res.outputFiles[0].text;
// console.log(output)
eval(output);
unlink();
}));
//# sourceMappingURL=index.test.js.map
{
"name": "@esbuild-plugins/node-globals-polyfill",
"version": "0.1.0",
"version": "0.1.1",
"description": "",

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

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