pob 9.2.1 → 9.5.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/CHANGELOG.md CHANGED
@@ -3,6 +3,54 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [9.5.0](https://github.com/christophehurpeau/pob/compare/pob@9.4.0...pob@9.5.0) (2021-12-11)
7
+
8
+
9
+ ### Features
10
+
11
+ * **pob-babel:** include plugin-run as export ([9a4515d](https://github.com/christophehurpeau/pob/commit/9a4515d26d816df6f257a90647046c7da5d83a16))
12
+ * enable global testing in monorepo ([178775b](https://github.com/christophehurpeau/pob/commit/178775bb7fc971bc6a9712b105623508f739ba7b))
13
+
14
+
15
+
16
+
17
+
18
+ # [9.4.0](https://github.com/christophehurpeau/pob/compare/pob@9.3.1...pob@9.4.0) (2021-12-11)
19
+
20
+
21
+ ### Features
22
+
23
+ * monorepo testing generator ([b444042](https://github.com/christophehurpeau/pob/commit/b444042aa5203e4ac7a56a3d93f5a3b98c0fce11))
24
+
25
+
26
+
27
+
28
+
29
+ ## [9.3.1](https://github.com/christophehurpeau/pob/compare/pob@9.3.0...pob@9.3.1) (2021-12-11)
30
+
31
+ **Note:** Version bump only for package pob
32
+
33
+
34
+
35
+
36
+
37
+ # [9.3.0](https://github.com/christophehurpeau/pob/compare/pob@9.2.1...pob@9.3.0) (2021-12-11)
38
+
39
+
40
+ ### Bug Fixes
41
+
42
+ * **pob:** newline in ci workflow ([78652a1](https://github.com/christophehurpeau/pob/commit/78652a1a412e04ab63fdb5ca7139e86f6e6a3dad))
43
+
44
+
45
+ ### Features
46
+
47
+ * **pob:** ci build ([1d1e76b](https://github.com/christophehurpeau/pob/commit/1d1e76b64e81fb08f3c1ea4de26363d162c9a15f))
48
+ * **pob:** typescript dom condition ([eecb027](https://github.com/christophehurpeau/pob/commit/eecb027d4415a20dfcc5612082d9b6ee3ad6a205))
49
+
50
+
51
+
52
+
53
+
6
54
  ## [9.2.1](https://github.com/christophehurpeau/pob/compare/pob@9.2.0...pob@9.2.1) (2021-12-11)
7
55
 
8
56
 
@@ -129,6 +129,7 @@ export default class PobAppGenerator extends Generator {
129
129
  this.composeWith('pob:common:typescript', {
130
130
  enable: babel,
131
131
  builddefs: false,
132
+ dom: browser,
132
133
  jsx,
133
134
  updateOnly: this.options.updateOnly,
134
135
  baseUrl: (() => {
@@ -1,6 +1,7 @@
1
1
  import fs from 'fs';
2
2
  import semver from 'semver';
3
3
  import Generator from 'yeoman-generator';
4
+ import inLerna from '../../../utils/inLerna.js';
4
5
  import * as packageUtils from '../../../utils/package.js';
5
6
 
6
7
  export default class CommonBabelGenerator extends Generator {
@@ -691,11 +692,7 @@ export default class CommonBabelGenerator extends Generator {
691
692
 
692
693
  /* pob-babel config */
693
694
 
694
- packageUtils.addOrRemoveDevDependencies(
695
- pkg,
696
- useBabel && this.options.isApp,
697
- ['@rollup/plugin-run'],
698
- );
695
+ packageUtils.removeDevDependencies(pkg, ['@rollup/plugin-run']);
699
696
 
700
697
  this.fs.delete('rollup.config.js');
701
698
  if (useBabel) {
@@ -726,7 +723,7 @@ export default class CommonBabelGenerator extends Generator {
726
723
  );
727
724
  }
728
725
 
729
- if (useBabel && this.options.testing) {
726
+ if (useBabel && this.options.testing && !inLerna) {
730
727
  // cjs for jest compat
731
728
  this.fs.copyTpl(
732
729
  this.templatePath('babel.config.cjs.ejs'),
@@ -734,6 +731,7 @@ export default class CommonBabelGenerator extends Generator {
734
731
  {
735
732
  hasReact,
736
733
  testing: this.options.testing,
734
+ jestExperimentalESM: !inLerna,
737
735
  },
738
736
  );
739
737
  } else {
@@ -1,4 +1,4 @@
1
- import run from '@rollup/plugin-run';
1
+ import run from 'pob-babel/plugin-run';
2
2
  import createRollupConfig from 'pob-babel/createRollupConfig.js';
3
3
 
4
4
  const watch = process.env.ROLLUP_WATCH === 'true';
@@ -9,6 +9,6 @@ module.exports = function babelConfig(api) {
9
9
 
10
10
  return {
11
11
  only: [path.resolve(__dirname, 'src')],
12
- presets: [require.resolve('pob-babel/preset')],
12
+ presets: [[require.resolve('pob-babel/preset')<% if (!jestExperimentalESM) { %>, { modules: 'commonjs' }<% } %>]],
13
13
  };
14
14
  };
@@ -337,7 +337,7 @@ export default class CommonLintGenerator extends Generator {
337
337
  ? `{${pkg.type === 'commonjs' ? 'mjs' : 'cjs'},js}`
338
338
  : `${hasReact ? '{ts,tsx}' : 'ts'}`;
339
339
 
340
- const jestOverride = !packageUtils.hasJest(pkg)
340
+ const jestOverride = !pkg.jest
341
341
  ? null
342
342
  : {
343
343
  files: [`**/*.test.${ext}`, `__tests__/**/*.${ext}`],
@@ -6,6 +6,12 @@ export default class CommonTestingGenerator extends Generator {
6
6
  constructor(args, opts) {
7
7
  super(args, opts);
8
8
 
9
+ this.option('monorepo', {
10
+ type: Boolean,
11
+ defaults: false,
12
+ desc: 'is root monorepo',
13
+ });
14
+
9
15
  this.option('enable', {
10
16
  type: Boolean,
11
17
  defaults: true,
@@ -44,10 +50,11 @@ export default class CommonTestingGenerator extends Generator {
44
50
  }
45
51
 
46
52
  default() {
47
- if (!inLerna) {
53
+ if (!inLerna || inLerna.root) {
48
54
  this.composeWith('pob:core:ci', {
49
55
  enable: this.options.ci,
50
- testing: this.options.testing,
56
+ testing: this.options.enable,
57
+ build: this.options.typescript,
51
58
  typescript: this.options.typescript,
52
59
  documentation: this.options.documentation,
53
60
  codecov: this.options.codecov,
@@ -72,6 +79,10 @@ export default class CommonTestingGenerator extends Generator {
72
79
  'babel-jest',
73
80
  ]);
74
81
 
82
+ const yoConfigPobMonorepo = inLerna && inLerna.pobMonorepoConfig;
83
+ const globalTesting = yoConfigPobMonorepo && yoConfigPobMonorepo.testing;
84
+ const enableForMonorepo = this.options.monorepo && globalTesting;
85
+
75
86
  if (!this.options.enable) {
76
87
  packageUtils.removeDevDependencies(pkg, ['jest', '@types/jest']);
77
88
 
@@ -90,81 +101,136 @@ export default class CommonTestingGenerator extends Generator {
90
101
 
91
102
  this.fs.writeJSON(this.destinationPath('package.json'), pkg);
92
103
  } else {
93
- const babelEnvs = pkg.pob.babelEnvs || [];
94
- const transpileWithBabel = packageUtils.transpileWithBabel(pkg);
95
-
96
- const shouldUseExperimentalVmModules =
97
- pkg.type === 'module' || transpileWithBabel;
98
-
99
- const jestCommand = `${
100
- shouldUseExperimentalVmModules
101
- ? 'NODE_OPTIONS=--experimental-vm-modules '
102
- : ''
103
- }jest`;
104
-
105
- packageUtils.addScripts(pkg, {
106
- test: jestCommand,
107
- 'test:watch': `${jestCommand} --watch`,
108
- 'generate:test-coverage': [
109
- 'rm -Rf docs/coverage/',
110
- `NODE_ENV=production ${
111
- transpileWithBabel ? 'BABEL_ENV=test ' : ''
112
- }${jestCommand} --coverage --coverageReporters=pob-lcov-reporter --coverageDirectory=docs/coverage/`,
113
- ].join(' ; '),
114
- });
115
-
116
- packageUtils.addDevDependencies(pkg, [
117
- 'pob-lcov-reporter',
118
- 'jest',
119
- '@types/jest',
120
- ]);
121
-
122
- const hasReact = transpileWithBabel && packageUtils.hasReact(pkg);
123
- const srcDirectory = transpileWithBabel ? 'src' : 'lib';
124
-
125
- if (!pkg.jest) pkg.jest = {};
126
- Object.assign(pkg.jest, {
127
- cacheDirectory: './node_modules/.cache/jest',
128
- testMatch: [
129
- `<rootDir>/${srcDirectory}/**/__tests__/**/*.${
130
- transpileWithBabel ? 'ts' : '?(m)js'
131
- }${hasReact ? '?(x)' : ''}`,
132
- `<rootDir>/${srcDirectory}/**/*.test.${
133
- transpileWithBabel ? 'ts' : '?(m)js'
134
- }${hasReact ? '?(x)' : ''}`,
135
- ],
136
- collectCoverageFrom: [
137
- `${srcDirectory}/**/*.${transpileWithBabel ? 'ts' : '?(m)js'}${
138
- hasReact ? '?(x)' : ''
139
- }`,
140
- ],
141
- moduleFileExtensions: [
142
- transpileWithBabel && 'ts',
143
- transpileWithBabel && hasReact && 'tsx',
144
- 'js',
145
- // 'jsx',
146
- 'json',
147
- ].filter(Boolean),
148
- extensionsToTreatAsEsm: [
149
- transpileWithBabel && '.ts',
150
- transpileWithBabel && hasReact && '.tsx',
151
- ].filter(Boolean),
152
- // transform: {
153
- // [`^.+\\.ts${hasReact ? 'x?' : ''}$`]: 'babel-jest',
154
- // },
155
- });
156
- delete pkg.jest.transform;
157
-
158
- if (
159
- babelEnvs.length === 0 ||
160
- babelEnvs.some((env) => env.target === 'node')
161
- ) {
162
- pkg.jest.testEnvironment = 'node';
104
+ packageUtils.addOrRemoveDevDependencies(
105
+ pkg,
106
+ enableForMonorepo || !globalTesting,
107
+ ['pob-lcov-reporter', 'jest', '@types/jest'],
108
+ );
109
+
110
+ if (this.options.monorepo && !globalTesting) {
111
+ delete pkg.jest;
112
+ packageUtils.addScripts(pkg, {
113
+ test: 'yarn workspaces foreach --parallel -Av run test',
114
+ });
115
+ } else if (this.options.monorepo) {
116
+ const shouldUseExperimentalVmModules = pkg.type === 'module';
117
+
118
+ const jestCommand = `${
119
+ shouldUseExperimentalVmModules
120
+ ? 'NODE_OPTIONS=--experimental-vm-modules '
121
+ : ''
122
+ }jest`;
123
+ const transpileWithBabel = yoConfigPobMonorepo.typescript;
124
+
125
+ packageUtils.addScripts(pkg, {
126
+ test: jestCommand,
127
+ 'generate:test-coverage': [
128
+ 'rm -Rf docs/coverage/',
129
+ `NODE_ENV=production ${
130
+ transpileWithBabel ? 'BABEL_ENV=test ' : ''
131
+ }${jestCommand} --coverage --coverageReporters=pob-lcov-reporter --coverageDirectory=docs/coverage/`,
132
+ ].join(' ; '),
133
+ });
134
+
135
+ if (!pkg.jest) pkg.jest = {};
136
+ Object.assign(pkg.jest, {
137
+ cacheDirectory: './node_modules/.cache/jest',
138
+ testEnvironment: 'node',
139
+ });
140
+
141
+ const hasReact = false;
142
+
143
+ if (shouldUseExperimentalVmModules) {
144
+ pkg.jest.extensionsToTreatAsEsm = [
145
+ transpileWithBabel && '.ts',
146
+ transpileWithBabel && hasReact && '.tsx',
147
+ ].filter(Boolean);
148
+ } else {
149
+ delete pkg.jest.extensionsToTreatAsEsm;
150
+ }
151
+ } else if (globalTesting) {
152
+ delete pkg.jest;
153
+ if (pkg.scripts) {
154
+ delete pkg.scripts.test;
155
+ delete pkg.scripts['generate:test-coverage'];
156
+ delete pkg.scripts['test:watch'];
157
+ }
163
158
  } else {
164
- delete pkg.jest.testEnvironment;
159
+ const babelEnvs = pkg.pob.babelEnvs || [];
160
+ const transpileWithBabel = packageUtils.transpileWithBabel(pkg);
161
+
162
+ const shouldUseExperimentalVmModules =
163
+ pkg.type === 'module' || (transpileWithBabel && !inLerna);
164
+
165
+ const jestCommand = `${
166
+ shouldUseExperimentalVmModules
167
+ ? 'NODE_OPTIONS=--experimental-vm-modules '
168
+ : ''
169
+ }jest`;
170
+
171
+ packageUtils.addScripts(pkg, {
172
+ test: jestCommand,
173
+ 'test:watch': `${jestCommand} --watch`,
174
+ 'generate:test-coverage': [
175
+ 'rm -Rf docs/coverage/',
176
+ `NODE_ENV=production ${
177
+ transpileWithBabel ? 'BABEL_ENV=test ' : ''
178
+ }${jestCommand} --coverage --coverageReporters=pob-lcov-reporter --coverageDirectory=docs/coverage/`,
179
+ ].join(' ; '),
180
+ });
181
+
182
+ const hasReact = transpileWithBabel && packageUtils.hasReact(pkg);
183
+ const srcDirectory = transpileWithBabel ? 'src' : 'lib';
184
+
185
+ if (!pkg.jest) pkg.jest = {};
186
+ Object.assign(pkg.jest, {
187
+ cacheDirectory: './node_modules/.cache/jest',
188
+ testMatch: [
189
+ `<rootDir>/${srcDirectory}/**/__tests__/**/*.${
190
+ transpileWithBabel ? 'ts' : '?(m)js'
191
+ }${hasReact ? '?(x)' : ''}`,
192
+ `<rootDir>/${srcDirectory}/**/*.test.${
193
+ transpileWithBabel ? 'ts' : '?(m)js'
194
+ }${hasReact ? '?(x)' : ''}`,
195
+ ],
196
+ collectCoverageFrom: [
197
+ `${srcDirectory}/**/*.${transpileWithBabel ? 'ts' : '?(m)js'}${
198
+ hasReact ? '?(x)' : ''
199
+ }`,
200
+ ],
201
+ moduleFileExtensions: [
202
+ transpileWithBabel && 'ts',
203
+ transpileWithBabel && hasReact && 'tsx',
204
+ 'js',
205
+ // 'jsx',
206
+ 'json',
207
+ ].filter(Boolean),
208
+ // transform: {
209
+ // [`^.+\\.ts${hasReact ? 'x?' : ''}$`]: 'babel-jest',
210
+ // },
211
+ });
212
+ delete pkg.jest.transform;
213
+
214
+ if (shouldUseExperimentalVmModules) {
215
+ pkg.jest.extensionsToTreatAsEsm = [
216
+ transpileWithBabel && '.ts',
217
+ transpileWithBabel && hasReact && '.tsx',
218
+ ].filter(Boolean);
219
+ } else {
220
+ delete pkg.jest.extensionsToTreatAsEsm;
221
+ }
222
+
223
+ if (
224
+ babelEnvs.length === 0 ||
225
+ babelEnvs.some((env) => env.target === 'node')
226
+ ) {
227
+ pkg.jest.testEnvironment = 'node';
228
+ } else {
229
+ delete pkg.jest.testEnvironment;
230
+ }
231
+
232
+ if (!transpileWithBabel) delete pkg.jest.transform;
165
233
  }
166
-
167
- if (!transpileWithBabel) delete pkg.jest.transform;
168
234
  }
169
235
 
170
236
  this.fs.writeJSON(this.destinationPath('package.json'), pkg);
@@ -20,6 +20,12 @@ export default class CommonTypescriptGenerator extends Generator {
20
20
  desc: 'enable jsx with typescript',
21
21
  });
22
22
 
23
+ this.option('dom', {
24
+ type: Boolean,
25
+ defaults: true,
26
+ desc: 'enable dom with typescript',
27
+ });
28
+
23
29
  this.option('baseUrl', {
24
30
  type: String,
25
31
  defaults: '',
@@ -57,7 +63,7 @@ export default class CommonTypescriptGenerator extends Generator {
57
63
  const tsconfigPath = this.destinationPath('tsconfig.json');
58
64
  const tsconfigBuildPath = this.destinationPath('tsconfig.build.json');
59
65
  if (this.options.enable) {
60
- const { jsx } = this.options;
66
+ const { jsx, dom } = this.options;
61
67
  let composite;
62
68
  let monorepoPackageNames;
63
69
  let monorepoPackageSrcPaths;
@@ -108,6 +114,7 @@ export default class CommonTypescriptGenerator extends Generator {
108
114
  monorepoPackageNames,
109
115
  monorepoPackageSrcPaths,
110
116
  jsx,
117
+ dom,
111
118
  baseUrl: this.options.baseUrl,
112
119
  },
113
120
  );
@@ -13,7 +13,7 @@
13
13
 
14
14
  "target": "esnext", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */
15
15
  "module": "esnext", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
16
- "lib": ["dom", "esnext"], /* Polyfills are imported either by babel or with polyfill.io */
16
+ "lib": [<%- dom ? '"dom", ' : '' %>"esnext"], /* Polyfills are imported either by babel or with polyfill.io */
17
17
  <%= jsx ? '' : '// ' %>"jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
18
18
  "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
19
19
 
@@ -13,6 +13,12 @@ export default class CoreCIGenerator extends Generator {
13
13
  desc: 'enable ci',
14
14
  });
15
15
 
16
+ this.option('build', {
17
+ type: Boolean,
18
+ defaults: true,
19
+ desc: 'enable build',
20
+ });
21
+
16
22
  this.option('typescript', {
17
23
  type: Boolean,
18
24
  defaults: true,
@@ -66,6 +72,7 @@ export default class CoreCIGenerator extends Generator {
66
72
  testing: this.options.testing && !!pkg.scripts.test,
67
73
  checks: !!pkg.scripts && !!pkg.scripts.checks,
68
74
  documentation: this.options.documentation,
75
+ build: this.options.build,
69
76
  typescript: this.options.typescript,
70
77
  codecov: this.options.codecov,
71
78
  },
@@ -54,6 +54,12 @@ jobs:
54
54
  - name: Checks
55
55
  run: <%= packageManager %> run checks
56
56
 
57
+ <% } -%>
58
+ <% if (build) { -%>
59
+ - name: Build
60
+ run: yarn run build
61
+ if: startsWith(matrix.node-version, '16.')
62
+
57
63
  <% } -%>
58
64
  - name: Prettier
59
65
  run: <%= packageManager %> run lint:prettier
@@ -221,9 +221,12 @@ export default class PobLibGenerator extends Generator {
221
221
 
222
222
  const withBabel = babelEnvs.length > 0;
223
223
  const jsx = withBabel && pkg.pob.jsx === true;
224
+ const browser =
225
+ withBabel && babelEnvs.some((env) => env.target === 'browser');
224
226
 
225
227
  this.composeWith('pob:common:typescript', {
226
228
  enable: withBabel,
229
+ dom: browser,
227
230
  jsx,
228
231
  updateOnly: this.options.updateOnly,
229
232
  baseUrl: './src',
@@ -194,18 +194,19 @@ export default class PobMonorepoGenerator extends Generator {
194
194
  throw new Error('packages should not be empty');
195
195
  }
196
196
 
197
- this.composeWith('pob:core:ci', {
198
- enable: this.pobLernaConfig.ci,
199
- typescript: this.pobLernaConfig.typescript,
197
+ this.composeWith('pob:common:husky', {});
198
+
199
+ this.composeWith('pob:common:testing', {
200
+ monorepo: true,
201
+ enable: this.pobLernaConfig.testing,
200
202
  testing: this.pobLernaConfig.testing,
201
- codecov: this.pobLernaConfig.codecov,
202
- documentation: this.pobLernaConfig.documentation,
203
- updateOnly: this.options.updateOnly,
203
+ typescript: this.pobLernaConfig.typescript,
204
+ documentation: !!this.pobLernaConfig.documentation,
205
+ codecov: this.pobLernaConfig.testing && this.pobLernaConfig.codecov,
206
+ ci: this.pobLernaConfig.ci,
204
207
  packageManager: this.options.packageManager,
205
208
  });
206
209
 
207
- this.composeWith('pob:common:husky', {});
208
-
209
210
  this.composeWith('pob:common:format-lint', {
210
211
  monorepo: true,
211
212
  documentation: this.pobLernaConfig.documentation,
@@ -152,19 +152,6 @@ export default class MonorepoLernaGenerator extends Generator {
152
152
 
153
153
  packageUtils.removeDevDependencies(pkg, ['standard-version']);
154
154
 
155
- const getPobConfig = (config) => ({
156
- ...(config &&
157
- config.pob &&
158
- (config.pob['pob-config'] || config.pob.lib || config.pob.app)),
159
- });
160
- // ynnub doesnt use babel but still have typescript
161
- // const withTypescript = this.packagePaths.some((packagePath) =>
162
- // this.fs.exists(this.destinationPath(`${packagePath}/tsconfig.json`)),
163
- // );
164
- const withTests = this.packagesConfig.some(
165
- (config) => getPobConfig(config).testing,
166
- );
167
-
168
155
  const monorepoConfig = this.config.get('monorepo');
169
156
  const packageManager = this.npm ? 'npm' : 'yarn';
170
157
  const useYarnWorkspacesCommand =
@@ -205,14 +192,6 @@ export default class MonorepoLernaGenerator extends Generator {
205
192
  ),
206
193
  );
207
194
 
208
- packageUtils.addOrRemoveScripts(pkg, withTests, {
209
- test: `${
210
- useYarnWorkspacesCommand
211
- ? 'yarn workspaces foreach --parallel -Av run'
212
- : 'lerna run --stream'
213
- } test`,
214
- });
215
-
216
195
  packageUtils.addOrRemoveScripts(pkg, withBabel, {
217
196
  build: `${
218
197
  useYarnWorkspacesCommand
@@ -37,9 +37,6 @@ export const hasReact = (pkg) =>
37
37
  (pkg.peerDependencies && pkg.peerDependencies.react)
38
38
  );
39
39
 
40
- export const hasJest = (pkg) =>
41
- !!(pkg.devDependencies && pkg.devDependencies.jest);
42
-
43
40
  export const sort = function sort(pkg) {
44
41
  return sortPkg(pkg);
45
42
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pob",
3
- "version": "9.2.1",
3
+ "version": "9.5.0",
4
4
  "description": "Pile of bones, library generator with git/babel/typescript/typedoc/readme/jest",
5
5
  "keywords": [
6
6
  "skeleton"
@@ -63,12 +63,12 @@
63
63
  "mem-fs-editor": "8.1.2",
64
64
  "minimist-argv": "^1.1.0",
65
65
  "parse-author": "^2.0.0",
66
- "pob-dependencies": "^6.0.3",
66
+ "pob-dependencies": "^6.1.0",
67
67
  "prettier": "2.5.1",
68
68
  "semver": "^7.3.4",
69
69
  "update-notifier": "^5.0.1",
70
70
  "yeoman-environment": "^3.5.1",
71
71
  "yeoman-generator": "^5.4.0"
72
72
  },
73
- "gitHead": "a57636519e371ba9e98391a04ab2b7389abf1aca"
73
+ "gitHead": "48b073ef8e253234b0b08f69a250befe044dcc58"
74
74
  }