rollup-plugin-web-worker-loader
Advanced tools
Comparing version 0.8.0 to 0.8.1
{ | ||
"name": "rollup-plugin-web-worker-loader", | ||
"version": "0.8.0", | ||
"version": "0.8.1", | ||
"description": "Rollup plugin to handle Web Workers", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -52,3 +52,6 @@ # rollup-plugin-web-worker-loader | ||
inline?: boolean, // should the worker code be inlined (Base64). Default: true | ||
forceInlne?: boolean, // *EXPERIMENTAL* when inlined, forces the code to be included every time it is imported | ||
// useful when using code splitting: Default: false | ||
preserveSource?: boolean, // when inlined and this option is enabled, the full source code is included in the | ||
@@ -55,0 +58,0 @@ // built file, otherwise it's embedded as a base64 string. Default: false |
@@ -0,1 +1,2 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
@@ -15,4 +16,7 @@ const rollup = require('rollup'); | ||
const pattern = config && config.hasOwnProperty('pattern') ? config.pattern : /web-worker:(.+)/; | ||
let inline = config && config.hasOwnProperty('inline') ? config.inline : true; | ||
const forceInline = inline && config && config.hasOwnProperty('forceInline') ? config.forceInline : false; | ||
const helperPattern = /rollup-plugin-web-worker-loader::helper(?:::[0-9]+)?$/; | ||
const idMap = new Map(); | ||
@@ -23,2 +27,3 @@ const exclude = new Set(); | ||
let configuredFileName = null; | ||
let forceInlineCounter = 0; | ||
@@ -39,3 +44,46 @@ return { | ||
projectOptions.plugins = plugins; | ||
basePath = path.dirname(options.input); | ||
const cwd = process.cwd(); | ||
if (typeof options.input === 'string') { | ||
try { | ||
const entry = require.resolve(options.input, {paths:[cwd]}); | ||
basePath = path.dirname(entry); | ||
} catch (e) {} | ||
} else if (Array.isArray(options.input)) { | ||
let componentCount = Number.MAX_SAFE_INTEGER; | ||
let shortestPath = null; | ||
for (let i = 0,n = options.input.length; i < n; ++i) { | ||
try { | ||
const entry = require.resolve(options.input[i], {paths:[cwd]}); | ||
const entryPath = path.dirname(entry); | ||
const components = entryPath.split(path.sep); | ||
if (components.length < componentCount) { | ||
componentCount = components.length; | ||
shortestPath = entryPath; | ||
} | ||
} catch (e) {} | ||
} | ||
basePath = shortestPath; | ||
} else { | ||
const keys = Object.keys(options.input); | ||
let componentCount = Number.MAX_SAFE_INTEGER; | ||
let shortestPath = null; | ||
for (let i = 0, n = keys.length; i < n; ++i) { | ||
const input = options.input[keys[i]]; | ||
try { | ||
const entry = require.resolve(input, {paths:[cwd]}); | ||
const entryPath = path.dirname(entry); | ||
const components = entryPath.split(path.sep); | ||
if (components.length < componentCount) { | ||
componentCount = components.length; | ||
shortestPath = entryPath; | ||
} | ||
} catch (e) {} | ||
} | ||
basePath = shortestPath; | ||
} | ||
if (!basePath) { | ||
basePath = '.'; | ||
} | ||
} | ||
@@ -50,2 +98,5 @@ } | ||
if (importee === 'rollup-plugin-web-worker-loader::helper') { | ||
if (forceInline) { | ||
return `${importee}::${forceInlineCounter++}`; | ||
} | ||
return path.resolve(__dirname, 'WorkerLoaderHelper.js'); | ||
@@ -66,4 +117,4 @@ } else if (match && match.length) { | ||
if (target) { | ||
const prefixed = `\0rollup-plugin-worker-loader::module:${name}`; | ||
if (!idMap.has(prefixed) && !exclude.has(target)) { | ||
const prefixed = `\0rollup-plugin-worker-loader::module:${forceInline ? `:${forceInlineCounter++}:` : ''}${name}`; | ||
if (!idMap.has(prefixed)) { | ||
const inputOptions = Object.assign({}, projectOptions, { | ||
@@ -79,2 +130,5 @@ input: target, | ||
}); | ||
} | ||
if (idMap.has(prefixed)) { | ||
return prefixed; | ||
@@ -91,3 +145,10 @@ } | ||
return new Promise((resolve, reject) => { | ||
if (idMap.has(id) && !exclude.has(id)) { | ||
if (helperPattern.test(id)) { | ||
fs.readFile(path.resolve(__dirname, 'WorkerLoaderHelper.js'), 'utf8', (err, data) => { | ||
if (err) { | ||
reject(err); | ||
} | ||
resolve(data); | ||
}); | ||
} else if (idMap.has(id) && !exclude.has(id)) { | ||
if (!inline) { | ||
@@ -94,0 +155,0 @@ /* inline requires rollup version 1.9.2 or higher */ |
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
43230
411
85
6