arc-plugin-esbuild
Advanced tools
Comparing version 2.3.1 to 2.3.2
@@ -19,7 +19,2 @@ declare const plugin: { | ||
}; | ||
watcher({ filename }: { | ||
filename: string; | ||
event: 'add' | 'update' | 'remove'; | ||
inventory: any; | ||
}): Promise<void>; | ||
}; | ||
@@ -26,0 +21,0 @@ export default plugin; |
@@ -9,2 +9,3 @@ 'use strict'; | ||
var globStandard = require('glob'); | ||
var watch = require('node-watch'); | ||
@@ -14,2 +15,3 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } | ||
var globStandard__default = /*#__PURE__*/_interopDefaultLegacy(globStandard); | ||
var watch__default = /*#__PURE__*/_interopDefaultLegacy(watch); | ||
@@ -29,5 +31,45 @@ async function buildFunction(entry) { | ||
const startWatch = async ({ projectDir, settings, callback }) => { | ||
const outputs = new Set(); | ||
for (const { dest } of settings) { | ||
outputs.add(dest); | ||
} | ||
const onWatch = async (_evt, _name) => { | ||
if (callback) { | ||
callback(); | ||
} | ||
await Promise.all(settings.map(async (buildSetting) => { | ||
await buildFunction(buildSetting); | ||
})); | ||
}; | ||
const config = { | ||
recursive: true, | ||
filter(file, skip) { | ||
if (outputs.has(file)) { | ||
return false; | ||
} | ||
// skip node_modules | ||
if (/\/node_modules/.test(file)) { | ||
return skip; | ||
} | ||
// skip .git folder | ||
if (/\.git/.test(file)) { | ||
return skip; | ||
} | ||
// only watch for relevant files | ||
return /\.(ts|js|graphql|arc|)$/.test(file); | ||
}, | ||
}; | ||
const watcher = watch__default["default"](projectDir, config, onWatch); | ||
await onWatch(); | ||
return { | ||
close() { | ||
watcher.close(); | ||
}, | ||
}; | ||
}; | ||
const glob = util.promisify(globStandard__default["default"]); | ||
const logger = utils.updater('esbuild', {}); | ||
let _esbuild = undefined; | ||
let stopWatch = null; | ||
const plugin = { | ||
@@ -97,5 +139,5 @@ deploy: { | ||
const srcDir = inventory.inv._project.src; | ||
const projectDir = inventory.inv._project.cwd; | ||
const entryPattern = path.join(srcDir, '**', entryFilePattern); | ||
const entryFiles = await glob(entryPattern, { ignore: ['./src/macros/**', './src/**/node_modules/**', './src/plugins/**'] }); | ||
const outputs = new Set(); | ||
const settings = entryFiles.map(src => { | ||
@@ -107,3 +149,2 @@ const sourceFile = path.basename(src); | ||
} | ||
outputs.add(dest); | ||
return { | ||
@@ -116,8 +157,12 @@ src, | ||
}); | ||
_esbuild = { srcDir, settings, outputs }; | ||
await Promise.all(settings.map(async (buildSetting) => { | ||
await buildFunction(buildSetting); | ||
})); | ||
logger.status('Starting up watch process...'); | ||
stopWatch = await startWatch({ projectDir, settings }); | ||
logger.done('Started'); | ||
}, | ||
async end({ inventory, arc }) { | ||
if (!stopWatch) { | ||
return; | ||
} | ||
logger.status('Stopping watch process...'); | ||
stopWatch.close(); | ||
logger.status('deleting build artifacts...'); | ||
@@ -147,18 +192,2 @@ const { entryFilePattern, target, external } = getOptions(arc); | ||
}, | ||
async watcher({ filename }) { | ||
if (!_esbuild) { | ||
logger.status('Unable to read settings'); | ||
return; | ||
} | ||
const { settings, outputs } = _esbuild; | ||
if (outputs.has(filename)) { | ||
return; | ||
} | ||
if (!/\.(ts|js|graphql|arc|)$/.test(filename)) { | ||
return; | ||
} | ||
await Promise.all(settings.map(async (buildSetting) => { | ||
await buildFunction(buildSetting); | ||
})); | ||
}, | ||
}; | ||
@@ -165,0 +194,0 @@ function getOptions(arc) { |
{ | ||
"name": "arc-plugin-esbuild", | ||
"version": "2.3.1", | ||
"version": "2.3.2", | ||
"description": "Use Typescript and esbuild with arc.codes!", | ||
@@ -35,3 +35,4 @@ "types": "dist/index.d.ts", | ||
"fs-extra": "^10.1.0", | ||
"glob": "^8.0.3" | ||
"glob": "^8.0.3", | ||
"node-watch": "^0.7.3" | ||
}, | ||
@@ -38,0 +39,0 @@ "peerDependencies": { |
Sorry, the diff of this file is not supported yet
36271
475
5
+ Addednode-watch@^0.7.3
+ Addedcross-spawn@7.0.3(transitive)
+ Addedforeground-child@3.1.1(transitive)
+ Addedisexe@2.0.0(transitive)
+ Addednode-watch@0.7.4(transitive)
+ Addedpath-key@3.1.1(transitive)
+ Addedshebang-command@2.0.0(transitive)
+ Addedshebang-regex@3.0.0(transitive)
+ Addedsignal-exit@4.1.0(transitive)
+ Addedwhich@2.0.2(transitive)