prod-files 0.1.0 → 0.1.2

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.
Files changed (2) hide show
  1. package/index.mjs +21 -6
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -272,7 +272,7 @@ export function printDiff({ prunedSize, startTime, itemCount, originalSize }) {
272
272
  /**
273
273
  * @typedef Args
274
274
  * @type {object}
275
- * @property {string} path - Path to node_modules
275
+ * @property {string} [path] - Path to node_modules
276
276
  * @property {string[]} include - New glob pattern
277
277
  * @property {string[]} exclude - Existing glob pattern
278
278
  * @property {boolean} help - Prints help
@@ -299,7 +299,6 @@ function handleArgs() {
299
299
  noSize: { type: 'boolean', short: 'n', default: false },
300
300
  },
301
301
  })
302
- if (!path) throw bail('Path not defined', undefined, true)
303
302
 
304
303
  return { ...values, path }
305
304
  } catch (err) {
@@ -644,9 +643,13 @@ export function compactPaths(paths) {
644
643
  return compact
645
644
  }
646
645
 
646
+ /**
647
+ * @typedef {Args & { path: string }} ArgsWithRequiredPath
648
+ */
649
+
647
650
  /**
648
651
  * Removes unneeded files from node_modules
649
- * @param {Args} opts
652
+ * @param {ArgsWithRequiredPath} opts
650
653
  */
651
654
  export async function prune(opts) {
652
655
  const startTime = Date.now()
@@ -684,7 +687,9 @@ export async function prune(opts) {
684
687
  return results
685
688
  }
686
689
 
687
- const runAsScript = process.argv[1] === import.meta.filename
690
+ const entry = process.argv[1]
691
+ const runAsScript =
692
+ entry && import.meta.filename.endsWith(entry.replace(process.cwd(), ''))
688
693
 
689
694
  if (runAsScript) {
690
695
  const args = handleArgs()
@@ -699,6 +704,16 @@ if (runAsScript) {
699
704
  process.exit(0)
700
705
  }
701
706
 
702
- await validateNodeModulesPath(args.path)
703
- await prune(args)
707
+ // Should have a path by now
708
+ if (!args.path) {
709
+ throw bail(
710
+ undefined,
711
+ 'Path not defined. Usage: prod-files <path-to-node-modules>'
712
+ )
713
+ }
714
+
715
+ const argsWithPath = /** @type {ArgsWithRequiredPath} */ (args)
716
+
717
+ await validateNodeModulesPath(argsWithPath.path)
718
+ await prune(argsWithPath)
704
719
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prod-files",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Keep only prod files by pruning non-prod files from node_modules before deploying",
5
5
  "keywords": [
6
6
  "clean",