fix(core): update

This commit is contained in:
Philipp Kunz 2019-01-26 02:30:59 +01:00
parent 7f0a2ae48d
commit 0ef30f31f9
2 changed files with 16 additions and 15 deletions

View File

@ -1,10 +1,9 @@
const path = require('path'); import * as plugins from './parcel-plugin-wrapper.plugins';
const fs = require('fs');
const mainExport = bundler => { module.exports = bundler => {
const readAsset = pathArg => { const readAsset = pathArg => {
try { try {
return fs.readFileSync(pathArg, 'utf8'); return plugins.fs.readFileSync(pathArg, 'utf8');
} catch (e) { } catch (e) {
console.error('file is invalid'); console.error('file is invalid');
throw e; throw e;
@ -12,7 +11,7 @@ const mainExport = bundler => {
}; };
const writeAsset = (name, { header = '', footer = '' }) => { const writeAsset = (name, { header = '', footer = '' }) => {
fs.writeFileSync( plugins.fs.writeFileSync(
name, name,
`${header} `${header}
${readAsset(name)} ${readAsset(name)}
@ -28,17 +27,17 @@ ${footer}`
writeAsset(name, wrappingCode); writeAsset(name, wrappingCode);
} }
bundle.childBundles.forEach(function(bundle) { bundle.childBundles.forEach((bundleArg) => {
processAsset(bundle, processFn); processAsset(bundleArg, processFn);
}); });
}; };
bundler.on('bundled', async bundle => { bundler.on('bundled', async bundleArg => {
try { try {
const CWD = process.cwd(); const CWD = process.cwd();
const processFn = require(path.join(CWD, '.assetWrapper.js')); const processFn = require(plugins.path.join(CWD, '.assetWrapper.js'));
if (processFn && typeof processFn === 'function') { if (processFn && typeof processFn === 'function') {
await processAsset(bundle, processFn); await processAsset(bundleArg, processFn);
} }
} catch (error) { } catch (error) {
console.warn( console.warn(
@ -47,5 +46,3 @@ ${footer}`
} }
}); });
}; };
export default mainExport;

View File

@ -1,4 +1,8 @@
const removeme = {}; // node native scope
import * as path from 'path';
import * as fs from 'fs';
export { export {
removeme path,
} fs
};