copy-globs-webpack-plugin
Advanced tools
Comparing version 0.2.0 to 0.3.0
814
index.js
@@ -1,359 +0,569 @@ | ||
"use strict"; | ||
/* This header is placed at the beginning of the output file and defines the | ||
special `__require`, `__getFilename`, and `__getDirname` functions. | ||
*/ | ||
(function () { | ||
var __modules = {}, | ||
__modulesCache = {}, | ||
__moduleIsCached = {}; | ||
/* __modules is an Array of functions; each function is a module added | ||
to the project */ | ||
var __modules = {}, | ||
function __require(uid, parentUid) { | ||
if (!__moduleIsCached[uid]) { | ||
__modulesCache[uid] = { "exports": {}, "loaded": false }; | ||
__moduleIsCached[uid] = true; | ||
if (uid === 0 && typeof require === "function") { | ||
require.main = __modulesCache[0]; | ||
} else { | ||
__modulesCache[uid].parent = __modulesCache[parentUid]; | ||
} | ||
/* __modulesCache is an Array of cached modules, much like | ||
`require.cache`. Once a module is executed, it is cached. */ | ||
__modulesCache = {}, | ||
__modules[uid].call(this, __modulesCache[uid], __modulesCache[uid].exports); | ||
__modulesCache[uid].loaded = true; | ||
} | ||
return __modulesCache[uid].exports; | ||
} | ||
/* __moduleIsCached - an Array of booleans, `true` if module is cached. */ | ||
__moduleIsCached = {}; | ||
/* If the module with the specified `uid` is cached, return it; | ||
otherwise, execute and cache it first. */ | ||
function __getFilename(path) { | ||
return require("path").resolve(__dirname + "/" + path); | ||
} | ||
function __require(uid, parentUid) { | ||
if (!__moduleIsCached[uid]) { | ||
// Populate the cache initially with an empty `exports` Object | ||
__modulesCache[uid] = { | ||
"exports": {}, | ||
"loaded": false | ||
}; | ||
__moduleIsCached[uid] = true; | ||
function __getDirname(path) { | ||
return require("path").resolve(__dirname + "/" + path + "/../"); | ||
} | ||
if (uid === 0 && typeof require === "function") { | ||
require.main = __modulesCache[0]; | ||
} else { | ||
__modulesCache[uid].parent = __modulesCache[parentUid]; | ||
} | ||
/* Note: if this module requires itself, or if its depenedencies | ||
require it, they will only see an empty Object for now */ | ||
// Now load the module | ||
__modules[0] = function (module, exports) { | ||
const glob = require('glob'); | ||
const chokidar = require('chokidar'); | ||
const WebpackFile = __require(1, 0); | ||
__modules[uid].call(this, __modulesCache[uid], __modulesCache[uid].exports); | ||
var _require = __require(2, 0); | ||
__modulesCache[uid].loaded = true; | ||
} | ||
const promisify = _require.promisify; | ||
return __modulesCache[uid].exports; | ||
} | ||
/* This function is the replacement for all `__filename` references within a | ||
project file. The idea is to return the correct `__filename` as if the | ||
file was not concatenated at all. Therefore, we should return the | ||
filename relative to the output file's path. | ||
`path` is the path relative to the output file's path at the time the | ||
project file was concatenated and added to the output file. | ||
*/ | ||
const errorMsg = msg => `\u001B[31m${msg}\u001B[0m`; | ||
function __getFilename(path) { | ||
return require("path").resolve(__dirname + "/" + path); | ||
} | ||
/* Same deal as __getFilename. | ||
`path` is the path relative to the output file's path at the time the | ||
project file was concatenated and added to the output file. | ||
*/ | ||
const GLOB_CWD_AUTO = null; | ||
const globAsync = promisify(glob); | ||
function __getDirname(path) { | ||
return require("path").resolve(__dirname + "/" + path + "/../"); | ||
} | ||
/********** End of header **********/ | ||
class PatternUndefinedError extends Error { | ||
constructor() { | ||
super(errorMsg('[copy-globs] You must provide glob pattern.')); | ||
this.name = 'PatternUndefinedError'; | ||
} | ||
} | ||
/********** Start module 0: /mnt/d/Development/Projects/qwp6t/copy-globs-webpack-plugin/src/CopyGlobsWebpackPlugin.js **********/ | ||
class ArgsArrayError extends TypeError { | ||
constructor() { | ||
super(errorMsg('[copy-globs] pattern cannot be an array.\n' + 'For multiple folders, use something like:\n\n' + ' +(images|fonts)/**/*\n\n' + 'See also: https://github.com/isaacs/node-glob#glob-primer\n')); | ||
this.name = 'ArgsArrayError'; | ||
} | ||
} | ||
const validatePattern = pattern => { | ||
if (pattern === undefined) { | ||
throw new PatternUndefinedError(); | ||
} | ||
if (Array.isArray(pattern)) { | ||
throw new ArgsArrayError(); | ||
} | ||
}; | ||
__modules[0] = function (module, exports) { | ||
const glob = require("glob"); | ||
const normalizeArguments = input => { | ||
validatePattern(input); | ||
const options = {}; | ||
if (typeof input === 'string') { | ||
options.pattern = input; | ||
} else { | ||
validatePattern(input.pattern); | ||
return input; | ||
} | ||
return options; | ||
}; | ||
const chokidar = require("chokidar"); | ||
module.exports = class { | ||
constructor(o) { | ||
const options = normalizeArguments(o); | ||
this.pattern = options.pattern; | ||
this.disable = options.disable; | ||
this.output = options.output || '[path][name].[ext]'; | ||
this.globOptions = Object.assign(options.globOptions || {}, { cwd: GLOB_CWD_AUTO }); | ||
this.globOptions.nodir = true; | ||
this.manifest = options.manifest || {}; | ||
this.files = []; | ||
this.watcher = null; | ||
} | ||
apply(compiler) { | ||
if (this.disable) { | ||
return; | ||
} | ||
this.compiler = compiler; | ||
this.resolveWorkingDirectory(); | ||
compiler.plugin('emit', this.emitHandler.bind(this)); | ||
compiler.plugin('after-emit', this.afterEmitHandler.bind(this)); | ||
compiler.plugin('watch-run', this.watcherHandler.bind(this)); | ||
} | ||
watcherHandler(compilation, callback) { | ||
if (!this.watcher) { | ||
this.startWatcher(); | ||
} | ||
callback(); | ||
} | ||
startWatcher() { | ||
this.watcher = chokidar.watch(this.pattern, { ignoreInitial: true, cwd: this.globOptions.cwd }).on('add', () => this.compiler.run(() => {})).on('change', () => this.compiler.run(() => {})).on('unlink', () => this.compiler.run(() => {})); | ||
} | ||
emitHandler(compilation, callback) { | ||
this.compilation = compilation; | ||
globAsync(this.pattern, this.globOptions).then(paths => Promise.all(paths.map(this.processAsset.bind(this))), err => compilation.errors.push(err)).then(() => { | ||
Object.keys(this.files).forEach(absoluteFrom => { | ||
const file = this.files[absoluteFrom]; | ||
this.manifest[file.relativeFrom] = file.webpackTo; | ||
this.compilation.assets[file.webpackTo] = { | ||
size: () => file.stat.size, | ||
source: () => file.content | ||
}; | ||
}); | ||
}).then(callback); | ||
} | ||
afterEmitHandler(compilation, callback) { | ||
Object.keys(this.files).filter(absoluteFrom => !compilation.fileDependencies.includes(absoluteFrom)).forEach(absoluteFrom => compilation.fileDependencies.push(absoluteFrom)); | ||
callback(); | ||
} | ||
resolveWorkingDirectory() { | ||
if (this.globOptions.cwd === GLOB_CWD_AUTO) { | ||
this.globOptions.cwd = this.compiler.options.context; | ||
} | ||
this.context = this.globOptions.cwd || this.compiler.options.context; | ||
} | ||
processAsset(relativeFrom) { | ||
if (this.compilation.assets[relativeFrom]) { | ||
return Promise.resolve(); | ||
} | ||
return this.addAsset(new WebpackFile(relativeFrom, this.output, this.context)); | ||
} | ||
addAsset(file) { | ||
const asset = this.getAsset(file.absoluteFrom); | ||
if (asset && asset.hash === file.hash) { | ||
return null; | ||
} | ||
this.files[file.absoluteFrom] = file; | ||
return file; | ||
} | ||
getAsset(absoluteFrom) { | ||
return this.files[absoluteFrom]; | ||
} | ||
}; | ||
const WebpackFile = __require(1, 0); | ||
return module.exports; | ||
}; | ||
const { | ||
promisify | ||
} = __require(2, 0); | ||
__modules[1] = function (module, exports) { | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const utils = require('loader-utils'); | ||
const Cache = __require(3, 1); | ||
const errorMsg = msg => `\u001B[31m${msg}\u001B[0m`; | ||
var _require2 = __require(2, 1); | ||
const GLOB_CWD_AUTO = null; | ||
const globAsync = promisify(glob); | ||
const fixPath = _require2.fixPath, | ||
interpolateName = _require2.interpolateName; | ||
class PatternUndefinedError extends Error { | ||
constructor() { | ||
super(errorMsg("[copy-globs] You must provide glob pattern.")); | ||
this.name = "PatternUndefinedError"; | ||
} | ||
} | ||
const destructive = ['relativeFrom', 'output', 'context']; | ||
const memoized = ['absoluteFrom', 'stat', 'content', 'webpackTo', 'hash']; | ||
const enumerable = destructive.concat(memoized); | ||
class ArgsArrayError extends TypeError { | ||
constructor() { | ||
super(errorMsg("[copy-globs] pattern cannot be an array.\n" + "For multiple folders, use something like:\n\n" + " +(images|fonts)/**/*\n\n" + "See also: https://github.com/isaacs/node-glob#glob-primer\n")); | ||
this.name = "ArgsArrayError"; | ||
} | ||
const data = new WeakMap(); | ||
} | ||
/** | ||
* Throws an error if pattern is an array or undefined | ||
* | ||
* @param pattern | ||
*/ | ||
class WebpackFile { | ||
constructor(relativeFrom, output = '[path][name].[ext]', context = process.cwd()) { | ||
this.data = new Cache(); | ||
this.relativeFrom = relativeFrom; | ||
this.context = context; | ||
this.output = output; | ||
} | ||
get data() { | ||
return data.get(this); | ||
} | ||
set data(cache) { | ||
if (cache instanceof Cache) { | ||
data.set(this, cache); | ||
} | ||
} | ||
reset() { | ||
this.data.forEach(prop => { | ||
if (!this.destructive.includes(prop)) { | ||
this.data.delete(prop); | ||
} | ||
}); | ||
} | ||
} | ||
Object.defineProperty(WebpackFile.prototype, 'dataMap', { | ||
enumerable: false, | ||
get() { | ||
return { | ||
absoluteFrom() { | ||
return path.resolve(this.context, this.relativeFrom); | ||
}, | ||
stat() { | ||
return fs.statSync(this.absoluteFrom); | ||
}, | ||
content() { | ||
return fs.readFileSync(this.absoluteFrom); | ||
}, | ||
webpackTo() { | ||
return fixPath(interpolateName(this.output, this.relativeFrom, this.content)); | ||
}, | ||
hash() { | ||
return utils.getHashDigest(this.content); | ||
} | ||
}; | ||
} | ||
}); | ||
const validatePattern = pattern => { | ||
if (pattern === undefined) { | ||
throw new PatternUndefinedError(); | ||
} | ||
Object.defineProperty(WebpackFile.prototype, 'destructive', { | ||
enumerable: false, | ||
value: destructive, | ||
writable: true | ||
}); | ||
if (Array.isArray(pattern)) { | ||
throw new ArgsArrayError(); | ||
} | ||
}; | ||
enumerable.forEach(property => Object.defineProperty(WebpackFile.prototype, property, { | ||
enumerable: true, | ||
set(value) { | ||
this.data.set(property, value); | ||
if (this.destructive.includes(property)) { | ||
this.reset(); | ||
} | ||
}, | ||
get() { | ||
if (this.dataMap[property] === undefined) { | ||
return this.data.get(property); | ||
} | ||
return this.data.get(property, this.dataMap[property].bind(this)); | ||
} | ||
})); | ||
const normalizeArguments = input => { | ||
validatePattern(input); | ||
const options = {}; | ||
module.exports = WebpackFile; | ||
if (typeof input === "string") { | ||
options.pattern = input; | ||
} else { | ||
validatePattern(input.pattern); | ||
return input; | ||
} | ||
return module.exports; | ||
}; | ||
return options; | ||
}; | ||
__modules[2] = function (module, exports) { | ||
const fixPath = __require(4, 2); | ||
const interpolateName = __require(5, 2); | ||
const memoize = __require(6, 2); | ||
const promisify = __require(7, 2); | ||
module.exports = class { | ||
constructor(o) { | ||
const options = normalizeArguments(o); | ||
this.pattern = options.pattern; | ||
this.disable = options.disable; | ||
this.output = options.output || "[path][name].[ext]"; | ||
this.globOptions = Object.assign(options.globOptions || {}, { | ||
cwd: GLOB_CWD_AUTO | ||
}); | ||
this.globOptions.nodir = true; | ||
this.manifest = options.manifest || {}; | ||
this.files = []; | ||
this.watcher = null; | ||
} | ||
module.exports = { fixPath, interpolateName, memoize, promisify }; | ||
apply(compiler) { | ||
if (this.disable) { | ||
return; | ||
} | ||
return module.exports; | ||
}; | ||
this.compiler = compiler; | ||
this.resolveWorkingDirectory(); | ||
__modules[3] = function (module, exports) { | ||
var _require3 = __require(2, 3); | ||
if (!this.compiler.hooks) { | ||
this.deprecated(); | ||
return; | ||
} | ||
const memoize = _require3.memoize; | ||
this.compiler.hooks.emit.tapAsync({ | ||
name: "CopyGlobsPlugin" | ||
}, this.emitHandler.bind(this)); | ||
this.compiler.hooks.afterEmit.tapAsync({ | ||
name: "CopyGlobsPlugin" | ||
}, this.afterEmitHandler.bind(this)); | ||
this.compiler.hooks.watchRun.tapAsync({ | ||
name: "CopyGlobsPlugin" | ||
}, this.watcherHandler.bind(this)); | ||
} | ||
deprecated() { | ||
this.compiler.plugin("emit", this.emitHandler.bind(this)); | ||
this.compiler.plugin("after-emit", this.afterEmitHandler.bind(this)); | ||
this.compiler.plugin("watch-run", this.watcherHandler.bind(this)); | ||
} | ||
module.exports = class Cache extends Map { | ||
constructor() { | ||
const self = new Map(); | ||
self.__proto__ = Cache.prototype; | ||
return self; | ||
} | ||
get(key, fn = null, ...args) { | ||
if (this.has(key) || !fn) { | ||
return Map.prototype.get.call(this, key); | ||
} | ||
this.set(key, memoize(fn, ...args)); | ||
return Map.prototype.get.call(this, key); | ||
} | ||
}; | ||
watcherHandler(compilation, callback) { | ||
if (!this.watcher) { | ||
this.startWatcher(); | ||
} | ||
return module.exports; | ||
}; | ||
callback(); | ||
} | ||
__modules[4] = function (module, exports) { | ||
module.exports = a => a.replace(/\\/g, '/'); | ||
startWatcher() { | ||
this.watcher = chokidar.watch(this.pattern, { | ||
ignoreInitial: true, | ||
cwd: this.globOptions.cwd | ||
}).on("add", () => this.compiler.run(() => {})).on("change", () => this.compiler.run(() => {})).on("unlink", () => this.compiler.run(() => {})); | ||
} | ||
return module.exports; | ||
}; | ||
emitHandler(compilation, callback) { | ||
this.compilation = compilation; | ||
globAsync(this.pattern, this.globOptions).then(paths => Promise.all(paths.map(this.processAsset.bind(this))), err => compilation.errors.push(err)).then(() => { | ||
Object.keys(this.files).forEach(absoluteFrom => { | ||
const file = this.files[absoluteFrom]; | ||
this.manifest[file.relativeFrom] = file.webpackTo; | ||
this.compilation.assets[file.webpackTo] = { | ||
size: () => file.stat.size, | ||
source: () => file.content | ||
}; | ||
}); | ||
}).then(callback); // eslint-disable-line promise/no-callback-in-promise | ||
} | ||
__modules[5] = function (module, exports) { | ||
const path = require('path'); | ||
const utils = require('loader-utils'); | ||
afterEmitHandler(compilation, callback) { | ||
Object.keys(this.files).filter(absoluteFrom => !compilation.fileDependencies.has(absoluteFrom)).forEach(absoluteFrom => compilation.fileDependencies.add(absoluteFrom)); | ||
callback(); | ||
} | ||
module.exports = (pattern, relativeFrom, content) => { | ||
let webpackTo = pattern; | ||
let resourcePath = relativeFrom; | ||
resolveWorkingDirectory() { | ||
if (this.globOptions.cwd === GLOB_CWD_AUTO) { | ||
this.globOptions.cwd = this.compiler.options.context; | ||
} | ||
const basename = path.basename(resourcePath); | ||
let dotRemoved = false; | ||
if (basename[0] === '.') { | ||
dotRemoved = true; | ||
resourcePath = path.join(path.dirname(resourcePath), basename.slice(1)); | ||
} | ||
this.context = this.globOptions.cwd || this.compiler.options.context; | ||
} | ||
if (!path.extname(resourcePath)) { | ||
webpackTo = webpackTo.replace(/\.?\[ext]/g, ''); | ||
} | ||
processAsset(relativeFrom) { | ||
if (this.compilation.assets[relativeFrom]) { | ||
return Promise.resolve(); | ||
} | ||
if (resourcePath.indexOf('/') < 0) { | ||
resourcePath = `/${resourcePath}`; | ||
} | ||
return this.addAsset(new WebpackFile(relativeFrom, this.output, this.context)); | ||
} | ||
webpackTo = utils.interpolateName({ resourcePath }, webpackTo, { content }); | ||
addAsset(file) { | ||
const asset = this.getAsset(file.absoluteFrom); | ||
if (dotRemoved) { | ||
webpackTo = path.join(path.dirname(webpackTo), `.${path.basename(webpackTo)}`); | ||
} | ||
return webpackTo; | ||
}; | ||
if (asset && asset.hash === file.hash) { | ||
return null; | ||
} | ||
return module.exports; | ||
}; | ||
this.files[file.absoluteFrom] = file; | ||
return file; | ||
} | ||
__modules[6] = function (module, exports) { | ||
let cache = new WeakMap(); | ||
getAsset(absoluteFrom) { | ||
return this.files[absoluteFrom]; | ||
} | ||
module.exports = function memoize(fn, ...args) { | ||
if (!cache.has(fn)) cache.set(fn, fn.apply(fn, args)); | ||
return cache.get(fn); | ||
}; | ||
}; | ||
return module.exports; | ||
}; | ||
/********** End of module 0: /mnt/d/Development/Projects/qwp6t/copy-globs-webpack-plugin/src/CopyGlobsWebpackPlugin.js **********/ | ||
module.exports.expire = (fn, ...args) => { | ||
cache.delete(fn, fn.apply(fn, args)); | ||
}; | ||
/********** Start module 1: /mnt/d/Development/Projects/qwp6t/copy-globs-webpack-plugin/src/WebpackFile.js **********/ | ||
module.exports.clear = () => { | ||
cache = new WeakMap(); | ||
}; | ||
return module.exports; | ||
}; | ||
__modules[1] = function (module, exports) { | ||
const fs = require("fs"); | ||
__modules[7] = function (module, exports) { | ||
module.exports = (callback, thisArg) => function () { | ||
const args = [].slice.call(arguments); | ||
return new Promise((resolve, reject) => { | ||
args.push((err, data) => err === null ? resolve(data) : reject(err)); | ||
return callback.apply(thisArg, args); | ||
}); | ||
}; | ||
const path = require("path"); | ||
return module.exports; | ||
}; | ||
const utils = require("loader-utils"); | ||
if (typeof module === "object") module.exports = __require(0);else return __require(0); | ||
})(); | ||
const Cache = __require(3, 1); | ||
const { | ||
fixPath, | ||
interpolateName | ||
} = __require(2, 1); | ||
const destructive = ["relativeFrom", "output", "context"]; | ||
const memoized = ["absoluteFrom", "stat", "content", "webpackTo", "hash"]; | ||
const enumerable = destructive.concat(memoized); | ||
const data = new WeakMap(); | ||
class WebpackFile { | ||
constructor(relativeFrom, output = "[path][name].[ext]", context = process.cwd()) { | ||
this.data = new Cache(); | ||
this.relativeFrom = relativeFrom; | ||
this.context = context; | ||
this.output = output; | ||
} | ||
get data() { | ||
return data.get(this); | ||
} | ||
set data(cache) { | ||
if (cache instanceof Cache) { | ||
data.set(this, cache); | ||
} | ||
} | ||
reset() { | ||
this.data.forEach(prop => { | ||
if (!this.destructive.includes(prop)) { | ||
this.data.delete(prop); | ||
} | ||
}); | ||
} | ||
} | ||
Object.defineProperty(WebpackFile.prototype, "dataMap", { | ||
enumerable: false, | ||
get() { | ||
return { | ||
absoluteFrom() { | ||
return path.resolve(this.context, this.relativeFrom); | ||
}, | ||
stat() { | ||
return fs.statSync(this.absoluteFrom); | ||
}, | ||
content() { | ||
return fs.readFileSync(this.absoluteFrom); | ||
}, | ||
webpackTo() { | ||
return fixPath(interpolateName(this.output, this.relativeFrom, this.content)); | ||
}, | ||
hash() { | ||
return utils.getHashDigest(this.content); | ||
} | ||
}; | ||
} | ||
}); | ||
/** Returns properties set by the constructor */ | ||
Object.defineProperty(WebpackFile.prototype, "destructive", { | ||
enumerable: false, | ||
value: destructive, | ||
writable: true | ||
}); | ||
/** Ensure all relevant properties are enumerable. */ | ||
enumerable.forEach(property => Object.defineProperty(WebpackFile.prototype, property, { | ||
enumerable: true, | ||
set(value) { | ||
this.data.set(property, value); | ||
if (this.destructive.includes(property)) { | ||
this.reset(); | ||
} | ||
}, | ||
get() { | ||
if (this.dataMap[property] === undefined) { | ||
return this.data.get(property); | ||
} | ||
return this.data.get(property, this.dataMap[property].bind(this)); | ||
} | ||
})); | ||
module.exports = WebpackFile; | ||
return module.exports; | ||
}; | ||
/********** End of module 1: /mnt/d/Development/Projects/qwp6t/copy-globs-webpack-plugin/src/WebpackFile.js **********/ | ||
/********** Start module 2: /mnt/d/Development/Projects/qwp6t/copy-globs-webpack-plugin/src/util.js **********/ | ||
__modules[2] = function (module, exports) { | ||
const fixPath = __require(4, 2); | ||
const interpolateName = __require(5, 2); | ||
const memoize = __require(6, 2); | ||
const promisify = __require(7, 2); | ||
module.exports = { | ||
fixPath, | ||
interpolateName, | ||
memoize, | ||
promisify | ||
}; | ||
return module.exports; | ||
}; | ||
/********** End of module 2: /mnt/d/Development/Projects/qwp6t/copy-globs-webpack-plugin/src/util.js **********/ | ||
/********** Start module 3: /mnt/d/Development/Projects/qwp6t/copy-globs-webpack-plugin/src/Cache.js **********/ | ||
__modules[3] = function (module, exports) { | ||
const { | ||
memoize | ||
} = __require(2, 3); | ||
module.exports = class Cache extends Map { | ||
constructor() { | ||
const self = new Map(); | ||
self.__proto__ = Cache.prototype; // eslint-disable-line no-proto | ||
return self; | ||
} | ||
get(key, fn = null, ...args) { | ||
if (this.has(key) || !fn) { | ||
return Map.prototype.get.call(this, key); | ||
} | ||
this.set(key, memoize(fn, ...args)); | ||
return Map.prototype.get.call(this, key); | ||
} | ||
}; | ||
return module.exports; | ||
}; | ||
/********** End of module 3: /mnt/d/Development/Projects/qwp6t/copy-globs-webpack-plugin/src/Cache.js **********/ | ||
/********** Start module 4: /mnt/d/Development/Projects/qwp6t/copy-globs-webpack-plugin/src/util/fixPath.js **********/ | ||
__modules[4] = function (module, exports) { | ||
/** | ||
* Converts backslashes (`\`) into slashes (`/`) | ||
* @param {string} path | ||
* @return {string} | ||
*/ | ||
module.exports = a => a.replace(/\\/g, '/'); | ||
return module.exports; | ||
}; | ||
/********** End of module 4: /mnt/d/Development/Projects/qwp6t/copy-globs-webpack-plugin/src/util/fixPath.js **********/ | ||
/********** Start module 5: /mnt/d/Development/Projects/qwp6t/copy-globs-webpack-plugin/src/util/interpolateName.js **********/ | ||
__modules[5] = function (module, exports) { | ||
const path = require('path'); | ||
const utils = require('loader-utils'); | ||
/** | ||
* Generate output name from output pattern | ||
* | ||
* @link https://github.com/kevlened/copy-webpack-plugin/blob/323b1d74ef35ed2221637d8028b1bef854deb523/src/writeFile.js#L31-L65 | ||
* @param {string} pattern | ||
* @param {string} relativeFrom | ||
* @param {binary} content | ||
* @return {string} | ||
*/ | ||
module.exports = (pattern, relativeFrom, content) => { | ||
let webpackTo = pattern; | ||
let resourcePath = relativeFrom; | ||
/* A hack so .dotted files don't get parsed as extensions */ | ||
const basename = path.basename(resourcePath); | ||
let dotRemoved = false; | ||
if (basename[0] === '.') { | ||
dotRemoved = true; | ||
resourcePath = path.join(path.dirname(resourcePath), basename.slice(1)); | ||
} | ||
/** | ||
* If it doesn't have an extension, remove it from the pattern | ||
* ie. [name].[ext] or [name][ext] both become [name] | ||
*/ | ||
if (!path.extname(resourcePath)) { | ||
webpackTo = webpackTo.replace(/\.?\[ext]/g, ''); | ||
} | ||
/** | ||
* A hack because loaderUtils.interpolateName doesn't | ||
* find the right path if no directory is defined | ||
* ie. [path] applied to 'file.txt' would return 'file' | ||
*/ | ||
if (resourcePath.indexOf('/') < 0) { | ||
resourcePath = `/${resourcePath}`; | ||
} | ||
webpackTo = utils.interpolateName({ | ||
resourcePath | ||
}, webpackTo, { | ||
content | ||
}); | ||
if (dotRemoved) { | ||
webpackTo = path.join(path.dirname(webpackTo), `.${path.basename(webpackTo)}`); | ||
} | ||
return webpackTo; | ||
}; | ||
return module.exports; | ||
}; | ||
/********** End of module 5: /mnt/d/Development/Projects/qwp6t/copy-globs-webpack-plugin/src/util/interpolateName.js **********/ | ||
/********** Start module 6: /mnt/d/Development/Projects/qwp6t/copy-globs-webpack-plugin/src/util/memoize.js **********/ | ||
__modules[6] = function (module, exports) { | ||
let cache = new WeakMap(); | ||
/** | ||
* @param {function} fn | ||
* @param {...any} [...args] | ||
* @return {any} - Results of fn(...args) | ||
*/ | ||
module.exports = function memoize(fn, ...args) { | ||
if (!cache.has(fn)) cache.set(fn, fn.apply(fn, args)); | ||
return cache.get(fn); | ||
}; | ||
/** | ||
* @param {function} fn | ||
* @param {...any} [...args] | ||
* @return {void} | ||
*/ | ||
module.exports.expire = (fn, ...args) => { | ||
cache.delete(fn, fn.apply(fn, args)); | ||
}; | ||
/** | ||
* @return {void} | ||
*/ | ||
module.exports.clear = () => { | ||
cache = new WeakMap(); | ||
}; | ||
return module.exports; | ||
}; | ||
/********** End of module 6: /mnt/d/Development/Projects/qwp6t/copy-globs-webpack-plugin/src/util/memoize.js **********/ | ||
/********** Start module 7: /mnt/d/Development/Projects/qwp6t/copy-globs-webpack-plugin/src/util/promisify.js **********/ | ||
__modules[7] = function (module, exports) { | ||
/** | ||
* Node-style asynchronous function. | ||
* | ||
* @callback nodeAsyncCallback | ||
* @param {string|null} err | ||
* @param {*} data | ||
*/ | ||
/** | ||
* Promisify node-style asynchronous functions | ||
* | ||
* @param {nodeAsyncCallback} callback - Function with node-style callback | ||
* @param {this} [thisArg] - Value to use as `this` when executing `callback`. | ||
* @return {Promise} - An instance of Promise | ||
*/ | ||
module.exports = (callback, thisArg) => function () { | ||
const args = [].slice.call(arguments); | ||
return new Promise((resolve, reject) => { | ||
args.push((err, data) => err === null ? resolve(data) : reject(err)); | ||
return callback.apply(thisArg, args); | ||
}); | ||
}; | ||
return module.exports; | ||
}; | ||
/********** End of module 7: /mnt/d/Development/Projects/qwp6t/copy-globs-webpack-plugin/src/util/promisify.js **********/ | ||
/********** Footer **********/ | ||
if (typeof module === "object") module.exports = __require(0);else return __require(0); | ||
})(); | ||
/********** End of footer **********/ |
{ | ||
"name": "copy-globs-webpack-plugin", | ||
"version": "0.2.0", | ||
"description": "Webpack plugin to copy static files ezpz.", | ||
"main": "index.js", | ||
"repository": "https://github.com/qwp6t/copy-globs-webpack-plugin.git", | ||
"author": "QWp6t", | ||
"license": "OSL-3.0", | ||
"xo": { | ||
"env": { "node": true, "es6": true }, | ||
"parserOptions": { | ||
"ecmaVersion": 2017, | ||
"sourceType": "module" | ||
}, | ||
"rules": { | ||
"unicorn/filename-case": 0, | ||
"object-curly-spacing": [2, "always"], | ||
"brace-style": [2, "1tbs", { "allowSingleLine": true }], | ||
"capitalized-comments": [0, "never"] | ||
} | ||
}, | ||
"babel": { | ||
"presets": [ | ||
["env", { "targets": { "node": 6.10 } }] | ||
], | ||
"comments": false | ||
}, | ||
"jest": { | ||
"coverageDirectory": "coverage" | ||
}, | ||
"dependencies": { | ||
"chokidar":"^1.6.1", | ||
"glob": "^7.1.1", | ||
"loader-utils": "^1.1.0" | ||
}, | ||
"devDependencies": { | ||
"babel-core": "^6.24.0", | ||
"babel-jest": "^19.0.0", | ||
"babel-preset-env": "^1.2.2", | ||
"jest": "^19.0.2", | ||
"module-concat": "^2.1.4", | ||
"webpack": "2.3.1", | ||
"xo": "^0.18.0" | ||
}, | ||
"scripts": { | ||
"prebuild": "npm run lint && npm test", | ||
"build": "node build/build.js", | ||
"lint": "xo src/* test/* build/*", | ||
"test": "jest", | ||
"coverage": "jest --coverage", | ||
"start": "jest --watch --notify", | ||
"prepublish": "npm build" | ||
} | ||
"name": "copy-globs-webpack-plugin", | ||
"version": "0.3.0", | ||
"description": "Webpack plugin to copy static files ezpz.", | ||
"main": "index.js", | ||
"repository": "https://github.com/qwp6t/copy-globs-webpack-plugin.git", | ||
"author": "QWp6t", | ||
"license": "OSL-3.0", | ||
"jest": { | ||
"coverageDirectory": "coverage" | ||
}, | ||
"dependencies": { | ||
"chokidar": "^2.0", | ||
"glob": "^7.1", | ||
"loader-utils": "^1.1.0" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "^7.1", | ||
"@babel/preset-env": "^7.1", | ||
"babel-core": "^7.0.0-bridge", | ||
"babel-jest": "^23.6", | ||
"husky": "^1.1", | ||
"jest": "^23.6", | ||
"module-concat": "^2.3", | ||
"prettier": "^1.14", | ||
"pretty-quick": "^1.8", | ||
"webpack": "4.20" | ||
}, | ||
"scripts": { | ||
"prebuild": "npm run lint && npm run test", | ||
"build": "node build/build.js", | ||
"lint": "prettier --write src/* test/* build/*", | ||
"test": "jest", | ||
"coverage": "jest --coverage", | ||
"start": "jest --watch --notify", | ||
"prepublish": "npm run build" | ||
}, | ||
"husky": { | ||
"hooks": { | ||
"pre-commit": "pretty-quick --staged" | ||
} | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
28681
437
0
10
+ Addedanymatch@2.0.0(transitive)
+ Addedchokidar@2.1.8(transitive)
+ Addedglob-parent@3.1.0(transitive)
+ Addedis-extglob@2.1.1(transitive)
+ Addedis-glob@3.1.04.0.3(transitive)
+ Addednormalize-path@3.0.0(transitive)
+ Addedpath-dirname@1.0.2(transitive)
+ Addedupath@1.2.0(transitive)
- Removedanymatch@1.3.2(transitive)
- Removedarr-diff@2.0.0(transitive)
- Removedarray-unique@0.2.1(transitive)
- Removedbraces@1.8.5(transitive)
- Removedchokidar@1.7.0(transitive)
- Removedexpand-brackets@0.1.5(transitive)
- Removedexpand-range@1.8.2(transitive)
- Removedextglob@0.3.2(transitive)
- Removedfilename-regex@2.0.1(transitive)
- Removedfill-range@2.2.4(transitive)
- Removedfor-own@0.1.5(transitive)
- Removedglob-base@0.3.0(transitive)
- Removedglob-parent@2.0.0(transitive)
- Removedis-dotfile@1.0.3(transitive)
- Removedis-equal-shallow@0.1.3(transitive)
- Removedis-extglob@1.0.0(transitive)
- Removedis-glob@2.0.1(transitive)
- Removedis-number@2.1.04.0.0(transitive)
- Removedis-posix-bracket@0.1.1(transitive)
- Removedis-primitive@2.0.0(transitive)
- Removedmath-random@1.0.4(transitive)
- Removedmicromatch@2.3.11(transitive)
- Removedobject.omit@2.0.1(transitive)
- Removedparse-glob@3.0.4(transitive)
- Removedpreserve@0.2.0(transitive)
- Removedrandomatic@3.1.1(transitive)
- Removedregex-cache@0.4.4(transitive)
Updatedchokidar@^2.0
Updatedglob@^7.1