@@ -29,8 +29,10 @@ const packagesDir = path.join(__dirname, '..', 'packages');
2929 * in the root package directory, along with the corresponding `.d.ts` files.
3030 *
3131 * @param {string } packageName
32+ * @param {Object } [options]
33+ * @param {boolean } [options.failOnError=true]
3234 */
33- const transpilePackage = async ( packageName ) => {
35+ const transpilePackage = async ( packageName , { failOnError = true } = { } ) => {
3436 try {
3537 // Compile TypeScript for the given project.
3638 // Reference the local `node_modules` version of `tsc` since on Windows
@@ -50,27 +52,30 @@ const transpilePackage = async (packageName) => {
5052 if ( ! ( await fs . pathExists ( mjsFile ) ) ) {
5153 const mjsSource = `export * from './${ assetBasename } .js';` ;
5254
53- // console.log({mjsFile, tsFile, assetBasename})
5455 fs . outputFileSync ( mjsFile , mjsSource ) ;
5556 }
5657 }
5758 } catch ( error ) {
58- logHelper . error ( error . stdout ) ;
59- throw error ;
59+ if ( failOnError ) {
60+ throw error ;
61+ } else {
62+ logHelper . error ( error . stdout ) ;
63+ }
6064 }
6165} ;
6266
6367/**
6468 * Transpiles a package iff it has TypeScript source files.
6569 *
6670 * @param {string } packagePath
71+ * @param {Object } [options]
6772 */
68- const transpilePackageOrSkip = async ( packagePath ) => {
69- // `packagePath` will be posix style because it comes from `glog ()`.
73+ const transpilePackageOrSkip = async ( packagePath , options ) => {
74+ // `packagePath` will be posix style because it comes from `glob ()`.
7075 const packageName = packagePath . split ( '/' ) . slice ( - 1 ) [ 0 ] ;
7176
7277 if ( await fs . pathExists ( path . join ( packagePath , 'tsconfig.json' ) ) ) {
73- await queueTranspile ( packageName ) ;
78+ await queueTranspile ( packageName , options ) ;
7479 } else {
7580 logHelper . log ( ol `Skipping package '${ packageName } '
7681 not yet converted to typescript.` ) ;
@@ -92,14 +97,16 @@ const debouncedTranspilerMap = {};
9297 * needed.
9398 *
9499 * @param {string } packageName
100+ * @param {Object } [options]
95101 */
96- const queueTranspile = async ( packageName ) => {
102+ const queueTranspile = async ( packageName , options ) => {
97103 if ( ! debouncedTranspilerMap [ packageName ] ) {
98104 debouncedTranspilerMap [ packageName ] = new AsyncDebounce ( async ( ) => {
99- await transpilePackage ( packageName ) ;
105+ await transpilePackage ( packageName , options ) ;
100106 } ) ;
101107 }
102108 await debouncedTranspilerMap [ packageName ] . call ( ) ;
109+ debouncedTranspilerMap [ packageName ] = null ;
103110} ;
104111
105112/**
@@ -123,16 +130,13 @@ const needsTranspile = (packageName) => {
123130gulp . task ( 'transpile-typescript' , gulp . series ( packageRunnner (
124131 'transpile-typescript' , 'all' , transpilePackageOrSkip ) ) ) ;
125132
126- gulp . task ( 'transpile-typescript:watch' , gulp . series ( packageRunnner (
127- 'transpile-typescript' , 'all' , transpilePackageOrSkip ) ) ) ;
128-
129133gulp . task ( 'transpile-typescript:watch' , ( ) => {
130134 const watcher = gulp . watch ( `./${ global . packageOrStar } /workbox-*/src/**/*.ts` ) ;
131135 watcher . on ( 'all' , async ( event , file ) => {
132136 const changedPkg = path . relative ( packagesDir , file ) . split ( path . sep ) [ 0 ] ;
133137
134138 pendingChangesMap [ changedPkg ] = true ;
135- await queueTranspile ( changedPkg ) ;
139+ await queueTranspile ( changedPkg , { failOnError : false } ) ;
136140 pendingChangesMap [ changedPkg ] = false ;
137141 } ) ;
138142} ) ;
0 commit comments