@lipemat/js-boilerplate-shared 0.0.5 → 0.1.0

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.
package/README.md CHANGED
@@ -1 +1,6 @@
1
1
  "# js-boilerplate-shared"
2
+
3
+
4
+ ## Scripts
5
+
6
+ * `js-boilerplate-shared__fix-pnp`: Fixes PNP compatibility issues
package/bin/fix-pnp.ts ADDED
@@ -0,0 +1,50 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * When using PNP loose mode, we get warnings for every module
5
+ * we access, not strictly declared.
6
+ *
7
+ * No built-in way in Yarn to disable the warnings.
8
+ * This script modifies to generate .pnp.js file to suppress
9
+ * all loose module warnings unless the environmental variable
10
+ * it set to display all warnings.
11
+ *
12
+ * @example
13
+ * ```json
14
+ * {
15
+ * "scripts": {
16
+ * "postinstall": "lipemat-js-boilerplate fix-pnp"
17
+ * }
18
+ * }
19
+ * ```
20
+ */
21
+
22
+ import fs from 'fs';
23
+
24
+ const PNP_FILES = [
25
+ './.pnp.js',
26
+ './.pnp.cjs',
27
+ './.pnp.mjs',
28
+ ];
29
+
30
+ PNP_FILES.forEach( PNP_FILE => {
31
+ if ( fs.existsSync( PNP_FILE ) ) {
32
+ fs.readFile( PNP_FILE, 'utf8', ( readError, data ) => {
33
+ if ( readError ) {
34
+ return console.error( readError );
35
+ }
36
+
37
+ const result = data.replace( /if \(reference != null\) {/, '// # Warnings suppressed via @lipemat/js-boilerplate/fix-pnp script. \n' +
38
+ 'if (! alwaysWarnOnFallback && reference != null) { \n' +
39
+ 'dependencyReference = reference; \n' +
40
+ '} else if (alwaysWarnOnFallback && reference != null) {' );
41
+
42
+ fs.writeFile( PNP_FILE, result, 'utf8', writeError => {
43
+ if ( writeError ) {
44
+ return console.error( writeError );
45
+ }
46
+ console.debug( `The ${PNP_FILE} file has been adjusted to no longer display warnings for loose modules.` );
47
+ } );
48
+ } );
49
+ }
50
+ } );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lipemat/js-boilerplate-shared",
3
- "version": "0.0.5",
3
+ "version": "0.1.0",
4
4
  "license": "MIT",
5
5
  "description": "Shared utilities for all @lipemat boilerplate packages",
6
6
  "engines": {
@@ -21,6 +21,9 @@
21
21
  "url": "https://github.com/lipemat/js-boilerplate-shared/issues"
22
22
  },
23
23
  "homepage": "https://github.com/lipemat/js-boilerplate-shared#readme",
24
+ "bin": {
25
+ "js-boilerplate-shared__fix-pnp": "bin/fix-pnp.ts"
26
+ },
24
27
  "scripts": {
25
28
  "build": "tsc --project ./bin",
26
29
  "lint": "eslint --fix --cache",