quackage 1.0.62 → 1.0.64

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -70,7 +70,13 @@ console.log(` > Building to [${_CONFIG.LibraryUniminifiedFileName}] and [${_CO
70
70
  console.log(`--> Gulp is taking over!`);
71
71
 
72
72
  const libBrowserify = require('browserify');
73
- const libGulp = require('gulp');
73
+
74
+ // Resolve gulp from the consuming project's CWD so that the task
75
+ // registry is shared with the gulp CLI (which also resolves from CWD).
76
+ // Without this, `file:` dev-dependency references to quackage cause
77
+ // two separate gulp instances — tasks registered here become invisible
78
+ // to the CLI, resulting in "Task never defined: default".
79
+ const libGulp = require(require.resolve('gulp', { paths: [process.cwd()] }));
74
80
 
75
81
  const libVinylSourceStream = require('vinyl-source-stream');
76
82
  const libVinylBuffer = require('vinyl-buffer');
@@ -78,28 +84,74 @@ const libVinylBuffer = require('vinyl-buffer');
78
84
  const libSourcemaps = require('gulp-sourcemaps');
79
85
  const libBabel = require('gulp-babel');
80
86
  const libTerser = require('gulp-terser');
87
+ const { Transform } = require('stream');
88
+
89
+ /**
90
+ * Create a configured browserify instance with common settings.
91
+ *
92
+ * Applies:
93
+ * - BrowserifyIgnore entries from config
94
+ * - Global transform to rewrite `require('node:xxx')` → `require('xxx')`
95
+ * (needed for packages like find-my-way v9 that use Node.js prefixed builtins)
96
+ *
97
+ * @param {object} pConfig - The gulpfile config object
98
+ * @returns {object} Configured browserify instance
99
+ */
100
+ function createBrowserifyInstance(pConfig)
101
+ {
102
+ var tmpBrowserify = libBrowserify(
103
+ {
104
+ entries: pConfig.EntrypointInputSourceFile,
105
+ standalone: pConfig.LibraryObjectName,
106
+ debug: true
107
+ });
108
+
109
+ // Ignore modules that should not be bundled (e.g. WASM loaders loaded via <script> tag)
110
+ if (Array.isArray(pConfig.BrowserifyIgnore))
111
+ {
112
+ for (var i = 0; i < pConfig.BrowserifyIgnore.length; i++)
113
+ {
114
+ tmpBrowserify.ignore(pConfig.BrowserifyIgnore[i]);
115
+ }
116
+ }
117
+
118
+ // Global transform: rewrite require('node:xxx') → require('xxx')
119
+ // Some npm packages (e.g. find-my-way v9) use the `node:` prefix for
120
+ // built-in modules, which browserify cannot resolve. This transform
121
+ // strips the prefix so browserify resolves the standard module name.
122
+ tmpBrowserify.transform(
123
+ function(pFile)
124
+ {
125
+ var tmpChunks = [];
126
+ return new Transform(
127
+ {
128
+ transform: function(pChunk, pEncoding, fCallback)
129
+ {
130
+ tmpChunks.push(pChunk);
131
+ fCallback();
132
+ },
133
+ flush: function(fCallback)
134
+ {
135
+ var tmpSource = Buffer.concat(tmpChunks).toString('utf8');
136
+ tmpSource = tmpSource.replace(
137
+ /require\(\s*['"]node:([^'"]+)['"]\s*\)/g,
138
+ "require('$1')"
139
+ );
140
+ this.push(tmpSource);
141
+ fCallback();
142
+ }
143
+ });
144
+ },
145
+ { global: true }
146
+ );
147
+
148
+ return tmpBrowserify;
149
+ }
81
150
 
82
151
  // Build the module for the browser
83
152
  libGulp.task('minified',
84
153
  () => {
85
- // set up the custom browserify instance for this task
86
- var tmpBrowserify = libBrowserify(
87
- {
88
- entries: _CONFIG.EntrypointInputSourceFile,
89
- standalone: _CONFIG.LibraryObjectName,
90
- debug: true
91
- });
92
-
93
- // Ignore modules that should not be bundled (e.g. WASM loaders loaded via <script> tag)
94
- if (Array.isArray(_CONFIG.BrowserifyIgnore))
95
- {
96
- for (var i = 0; i < _CONFIG.BrowserifyIgnore.length; i++)
97
- {
98
- tmpBrowserify.ignore(_CONFIG.BrowserifyIgnore[i]);
99
- }
100
- }
101
-
102
- return tmpBrowserify.bundle()
154
+ return createBrowserifyInstance(_CONFIG).bundle()
103
155
  .pipe(libVinylSourceStream(_CONFIG.LibraryMinifiedFileName))
104
156
  .pipe(libVinylBuffer())
105
157
  .pipe(libSourcemaps.init({loadMaps: true}))
@@ -114,24 +166,7 @@ libGulp.task('minified',
114
166
  // Build the module for the browser
115
167
  libGulp.task('debug',
116
168
  () => {
117
- // set up the custom browserify instance for this task
118
- var tmpBrowserify = libBrowserify(
119
- {
120
- entries: _CONFIG.EntrypointInputSourceFile,
121
- standalone: _CONFIG.LibraryObjectName,
122
- debug: true
123
- });
124
-
125
- // Ignore modules that should not be bundled (e.g. WASM loaders loaded via <script> tag)
126
- if (Array.isArray(_CONFIG.BrowserifyIgnore))
127
- {
128
- for (var i = 0; i < _CONFIG.BrowserifyIgnore.length; i++)
129
- {
130
- tmpBrowserify.ignore(_CONFIG.BrowserifyIgnore[i]);
131
- }
132
- }
133
-
134
- return tmpBrowserify.bundle()
169
+ return createBrowserifyInstance(_CONFIG).bundle()
135
170
  .pipe(libVinylSourceStream(_CONFIG.LibraryUniminifiedFileName))
136
171
  .pipe(libVinylBuffer())
137
172
  .pipe(libSourcemaps.init({loadMaps: true}))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quackage",
3
- "version": "1.0.62",
3
+ "version": "1.0.64",
4
4
  "description": "Building. Testing. Quacking. Reloading.",
5
5
  "main": "source/Quackage-CLIProgram.js",
6
6
  "scripts": {
@@ -69,7 +69,15 @@ class QuackageCommandBuild extends libCommandLineCommand
69
69
  }
70
70
 
71
71
  // ## .gulpfile-quackage-config.json
72
- libFS.writeFileSync(`${this.fable.AppData.CWD}/.gulpfile-quackage-config.json`, this.fable.parseTemplateByHash('Gulpfile-Configuration', pAction));
72
+ let tmpGulpfileConfigContent = this.fable.parseTemplateByHash('Gulpfile-Configuration', pAction);
73
+ // Allow per-action BrowserifyIgnore overrides from GulpExecutions entries
74
+ if (Array.isArray(pAction.BrowserifyIgnore) && pAction.BrowserifyIgnore.length > 0)
75
+ {
76
+ let tmpGulpfileConfig = JSON.parse(tmpGulpfileConfigContent);
77
+ tmpGulpfileConfig.BrowserifyIgnore = pAction.BrowserifyIgnore;
78
+ tmpGulpfileConfigContent = JSON.stringify(tmpGulpfileConfig, null, 4);
79
+ }
80
+ libFS.writeFileSync(`${this.fable.AppData.CWD}/.gulpfile-quackage-config.json`, tmpGulpfileConfigContent);
73
81
  // ## .gulpfile-quackage.js
74
82
  libFS.writeFileSync(`${this.fable.AppData.CWD}/.gulpfile-quackage.js`, this.fable.parseTemplateByHash('Gulpfile-QuackageBase', { AppData: this.fable.AppData, Record: pAction }));
75
83
  // ## gulpfile.js
@@ -336,39 +336,67 @@ ${tmpExampleListItems} </ul>
336
336
  }
337
337
 
338
338
  let tmpNpxLocation = this.resolveExecutable('npx');
339
+ let tmpNpmLocation = this.resolveExecutable('npm');
339
340
 
340
- this.fable.QuackageProcess.execute(
341
- tmpNpxLocation,
342
- ['quack', 'build'],
343
- { cwd: pExample.Path },
344
- (pBuildError) =>
345
- {
346
- if (pBuildError)
347
- {
348
- this.log.error(`Build error in [${pExample.Name}]: ${pBuildError.message}`);
349
- }
350
-
351
- if (tmpPackage.copyFiles || tmpPackage.copyFilesSettings)
341
+ // Install dependencies if node_modules does not exist
342
+ let tmpNodeModulesPath = libPath.join(pExample.Path, 'node_modules');
343
+ let tmpRunBuild = () =>
344
+ {
345
+ this.fable.QuackageProcess.execute(
346
+ tmpNpxLocation,
347
+ ['quack', 'build'],
348
+ { cwd: pExample.Path },
349
+ (pBuildError) =>
352
350
  {
353
- this.log.info(`Copying files for [${pExample.Name}] ...`);
354
- this.fable.QuackageProcess.execute(
355
- tmpNpxLocation,
356
- ['quack', 'copy'],
357
- { cwd: pExample.Path },
358
- (pCopyError) =>
359
- {
360
- if (pCopyError)
351
+ if (pBuildError)
352
+ {
353
+ this.log.error(`Build error in [${pExample.Name}]: ${pBuildError.message}`);
354
+ }
355
+
356
+ if (tmpPackage.copyFiles || tmpPackage.copyFilesSettings)
357
+ {
358
+ this.log.info(`Copying files for [${pExample.Name}] ...`);
359
+ this.fable.QuackageProcess.execute(
360
+ tmpNpxLocation,
361
+ ['quack', 'copy'],
362
+ { cwd: pExample.Path },
363
+ (pCopyError) =>
361
364
  {
362
- this.log.error(`Copy error in [${pExample.Name}]: ${pCopyError.message}`);
363
- }
364
- return fExampleCallback();
365
- });
366
- }
367
- else
365
+ if (pCopyError)
366
+ {
367
+ this.log.error(`Copy error in [${pExample.Name}]: ${pCopyError.message}`);
368
+ }
369
+ return fExampleCallback();
370
+ });
371
+ }
372
+ else
373
+ {
374
+ return fExampleCallback();
375
+ }
376
+ });
377
+ };
378
+
379
+ if (!libFS.existsSync(tmpNodeModulesPath))
380
+ {
381
+ this.log.info(`Installing dependencies for [${pExample.Name}] ...`);
382
+ this.fable.QuackageProcess.execute(
383
+ tmpNpmLocation,
384
+ ['install'],
385
+ { cwd: pExample.Path },
386
+ (pInstallError) =>
368
387
  {
369
- return fExampleCallback();
370
- }
371
- });
388
+ if (pInstallError)
389
+ {
390
+ this.log.error(`Install error in [${pExample.Name}]: ${pInstallError.message}`);
391
+ return fExampleCallback();
392
+ }
393
+ tmpRunBuild();
394
+ });
395
+ }
396
+ else
397
+ {
398
+ tmpRunBuild();
399
+ }
372
400
  },
373
401
  (pError) =>
374
402
  {