diff --git a/ts/index.ts b/ts/index.ts index a065e67..4283eec 100644 --- a/ts/index.ts +++ b/ts/index.ts @@ -1,10 +1,9 @@ -const path = require('path'); -const fs = require('fs'); +import * as plugins from './parcel-plugin-wrapper.plugins'; -const mainExport = bundler => { +module.exports = bundler => { const readAsset = pathArg => { try { - return fs.readFileSync(pathArg, 'utf8'); + return plugins.fs.readFileSync(pathArg, 'utf8'); } catch (e) { console.error('file is invalid'); throw e; @@ -12,7 +11,7 @@ const mainExport = bundler => { }; const writeAsset = (name, { header = '', footer = '' }) => { - fs.writeFileSync( + plugins.fs.writeFileSync( name, `${header} ${readAsset(name)} @@ -28,17 +27,17 @@ ${footer}` writeAsset(name, wrappingCode); } - bundle.childBundles.forEach(function(bundle) { - processAsset(bundle, processFn); + bundle.childBundles.forEach((bundleArg) => { + processAsset(bundleArg, processFn); }); }; - bundler.on('bundled', async bundle => { + bundler.on('bundled', async bundleArg => { try { 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') { - await processAsset(bundle, processFn); + await processAsset(bundleArg, processFn); } } catch (error) { console.warn( @@ -47,5 +46,3 @@ ${footer}` } }); }; - -export default mainExport; \ No newline at end of file diff --git a/ts/parcel-plugin-wrapper.plugins.ts b/ts/parcel-plugin-wrapper.plugins.ts index d00ae0c..8fb63b8 100644 --- a/ts/parcel-plugin-wrapper.plugins.ts +++ b/ts/parcel-plugin-wrapper.plugins.ts @@ -1,4 +1,8 @@ -const removeme = {}; +// node native scope +import * as path from 'path'; +import * as fs from 'fs'; + export { - removeme -} + path, + fs +};