From e1ab61cfcb1efb4fbbc44a3be557422866f70073 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Wed, 18 Nov 2020 12:35:35 -0500 Subject: [PATCH] chore: fix watcher config --- Gulpfile.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/Gulpfile.js b/Gulpfile.js index be30c73e94dd..8c4310342c74 100644 --- a/Gulpfile.js +++ b/Gulpfile.js @@ -22,8 +22,19 @@ const { terser: rollupTerser } = require("rollup-plugin-terser"); const defaultSourcesGlob = "./@(codemods|packages|eslint)/*/src/**/*.{js,ts}"; -function swapSrcWithLib(srcPath) { - const parts = srcPath.split(path.sep); +/** + * map source code path to the generated artifacts path + * @example + * mapSrcToLib("packages/babel-core/src/index.js") + * // returns "packages/babel-core/lib/index.js" + * @example + * mapSrcToLib("packages/babel-template/src/index.ts") + * // returns "packages/babel-template/lib/index.js" + * @param {string} srcPath + * @returns {string} + */ +function mapSrcToLib(srcPath) { + const parts = srcPath.replace(/\.ts$/, ".js").split(path.sep); parts[2] = "lib"; return parts.join(path.sep); } @@ -72,7 +83,7 @@ function buildBabel(exclude, sourcesGlob = defaultSourcesGlob) { return stream .pipe(errorsLogger()) - .pipe(newer({ dest: base, map: swapSrcWithLib })) + .pipe(newer({ dest: base, map: mapSrcToLib })) .pipe(compilationLogger()) .pipe( babel({ @@ -85,7 +96,7 @@ function buildBabel(exclude, sourcesGlob = defaultSourcesGlob) { .pipe( // Passing 'file.relative' because newer() above uses a relative // path and this keeps it consistent. - rename(file => path.resolve(file.base, swapSrcWithLib(file.relative))) + rename(file => path.resolve(file.base, mapSrcToLib(file.relative))) ) .pipe(gulp.dest(base)); }