react-native-builder-bob 0.38.0 → 0.38.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 (47) hide show
  1. package/lib/__fixtures__/project/MyNativeComponent.js +2 -0
  2. package/lib/__fixtures__/project/MyNativeComponent.js.map +1 -0
  3. package/lib/__fixtures__/project/NativeMyLib.js +2 -0
  4. package/lib/__fixtures__/project/NativeMyLib.js.map +1 -0
  5. package/lib/__fixtures__/project/code/$exports-input.js +62 -2
  6. package/lib/__fixtures__/project/code/$exports-input.js.map +1 -1
  7. package/lib/__fixtures__/project/code/$exports-output.js +62 -2
  8. package/lib/__fixtures__/project/code/$exports-output.js.map +1 -1
  9. package/lib/__fixtures__/project/code/$imports-input.js +20 -0
  10. package/lib/__fixtures__/project/code/$imports-input.js.map +1 -1
  11. package/lib/__fixtures__/project/code/$imports-output.js +20 -0
  12. package/lib/__fixtures__/project/code/$imports-output.js.map +1 -1
  13. package/lib/__fixtures__/project/code/MyNativeComponent.js +2 -0
  14. package/lib/__fixtures__/project/code/MyNativeComponent.js.map +1 -0
  15. package/lib/__fixtures__/project/code/NativeMyLib.js +2 -0
  16. package/lib/__fixtures__/project/code/NativeMyLib.js.map +1 -0
  17. package/lib/__tests__/{index.test.js → babel.test.js} +8 -1
  18. package/lib/__tests__/babel.test.js.map +1 -0
  19. package/lib/__tests__/init.test.js +78 -0
  20. package/lib/__tests__/init.test.js.map +1 -0
  21. package/lib/babel.js +13 -6
  22. package/lib/babel.js.map +1 -1
  23. package/lib/build.js +163 -0
  24. package/lib/build.js.map +1 -0
  25. package/lib/index.js +3 -433
  26. package/lib/index.js.map +1 -1
  27. package/lib/init.js +371 -0
  28. package/lib/init.js.map +1 -0
  29. package/lib/targets/commonjs.js +2 -0
  30. package/lib/targets/commonjs.js.map +1 -1
  31. package/lib/targets/module.js +2 -0
  32. package/lib/targets/module.js.map +1 -1
  33. package/lib/targets/typescript.js +48 -25
  34. package/lib/targets/typescript.js.map +1 -1
  35. package/lib/types.js.map +1 -1
  36. package/lib/utils/compile.js +57 -24
  37. package/lib/utils/compile.js.map +1 -1
  38. package/lib/utils/isCodegenSpec.js +11 -0
  39. package/lib/utils/isCodegenSpec.js.map +1 -0
  40. package/lib/utils/loadConfig.js +21 -0
  41. package/lib/utils/loadConfig.js.map +1 -0
  42. package/package.json +4 -3
  43. package/lib/__fixtures__/project/code/$alias-input.js +0 -8
  44. package/lib/__fixtures__/project/code/$alias-input.js.map +0 -1
  45. package/lib/__fixtures__/project/code/$alias-output.js +0 -8
  46. package/lib/__fixtures__/project/code/$alias-output.js.map +0 -1
  47. package/lib/__tests__/index.test.js.map +0 -1
package/lib/build.js ADDED
@@ -0,0 +1,163 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.args = void 0;
7
+ exports.build = build;
8
+ var _path = _interopRequireDefault(require("path"));
9
+ var _kleur = _interopRequireDefault(require("kleur"));
10
+ var logger = _interopRequireWildcard(require("./utils/logger"));
11
+ var _commonjs = _interopRequireDefault(require("./targets/commonjs"));
12
+ var _module = _interopRequireDefault(require("./targets/module"));
13
+ var _typescript = _interopRequireDefault(require("./targets/typescript"));
14
+ var _codegen = _interopRequireDefault(require("./targets/codegen"));
15
+ var _custom = _interopRequireDefault(require("./targets/custom"));
16
+ var _fsExtra = _interopRequireDefault(require("fs-extra"));
17
+ var _loadConfig = require("./utils/loadConfig");
18
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
19
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
20
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
21
+ const args = exports.args = {
22
+ target: {
23
+ type: 'string',
24
+ description: 'The target to build',
25
+ choices: ['commonjs', 'module', 'typescript', 'codegen']
26
+ }
27
+ };
28
+ async function build(argv) {
29
+ const root = process.cwd();
30
+ const projectPackagePath = _path.default.resolve(root, 'package.json');
31
+ if (!(await _fsExtra.default.pathExists(projectPackagePath))) {
32
+ throw new Error(`Couldn't find a 'package.json' file in '${root}'. Are you in a project folder?`);
33
+ }
34
+ const result = await (0, _loadConfig.loadConfig)();
35
+ if (!result?.config) {
36
+ logger.error(`No configuration found. Run '${argv.$0} init' to create one automatically.`);
37
+ process.exit(1);
38
+ }
39
+ const options = result.config;
40
+ if (!options.targets?.length) {
41
+ logger.error(`No targets found in the configuration in '${_path.default.relative(root, result.filepath)}'.`);
42
+ process.exit(1);
43
+ }
44
+ const source = options.source;
45
+ if (!source) {
46
+ logger.error(`No source option found in the configuration in '${_path.default.relative(root, result.filepath)}'.`);
47
+ process.exit(1);
48
+ }
49
+ const output = options.output;
50
+ if (!output) {
51
+ logger.error(`No source option found in the configuration in '${_path.default.relative(root, result.filepath)}'.`);
52
+ process.exit(1);
53
+ }
54
+ const exclude = options.exclude ?? '**/{__tests__,__fixtures__,__mocks__}/**';
55
+ const commonjs = options.targets?.some(t => Array.isArray(t) ? t[0] === 'commonjs' : t === 'commonjs');
56
+ const module = options.targets?.some(t => Array.isArray(t) ? t[0] === 'module' : t === 'module');
57
+ const variants = {
58
+ commonjs,
59
+ module
60
+ };
61
+ if (argv.target != null) {
62
+ buildTarget({
63
+ root,
64
+ target: argv.target,
65
+ source,
66
+ output,
67
+ exclude,
68
+ options,
69
+ variants
70
+ });
71
+ } else {
72
+ for (const target of options.targets) {
73
+ buildTarget({
74
+ root,
75
+ target,
76
+ source,
77
+ output,
78
+ exclude,
79
+ options,
80
+ variants
81
+ });
82
+ }
83
+ }
84
+ }
85
+ async function buildTarget({
86
+ root,
87
+ target,
88
+ source,
89
+ output,
90
+ exclude,
91
+ options,
92
+ variants
93
+ }) {
94
+ const targetName = Array.isArray(target) ? target[0] : target;
95
+ const targetOptions = Array.isArray(target) ? target[1] : undefined;
96
+ const report = logger.grouped(targetName);
97
+ switch (targetName) {
98
+ case 'commonjs':
99
+ await (0, _commonjs.default)({
100
+ root,
101
+ source: _path.default.resolve(root, source),
102
+ output: _path.default.resolve(root, output, 'commonjs'),
103
+ exclude,
104
+ options: targetOptions,
105
+ variants,
106
+ report
107
+ });
108
+ break;
109
+ case 'module':
110
+ await (0, _module.default)({
111
+ root,
112
+ source: _path.default.resolve(root, source),
113
+ output: _path.default.resolve(root, output, 'module'),
114
+ exclude,
115
+ options: targetOptions,
116
+ variants,
117
+ report
118
+ });
119
+ break;
120
+ case 'typescript':
121
+ {
122
+ const esm = options.targets?.some(t => {
123
+ if (Array.isArray(t)) {
124
+ const [name, options] = t;
125
+ if (name === 'module') {
126
+ return options && 'esm' in options && options?.esm;
127
+ }
128
+ }
129
+ return false;
130
+ }) ?? false;
131
+ await (0, _typescript.default)({
132
+ root,
133
+ source: _path.default.resolve(root, source),
134
+ output: _path.default.resolve(root, output, 'typescript'),
135
+ options: targetOptions,
136
+ esm,
137
+ variants,
138
+ report
139
+ });
140
+ }
141
+ break;
142
+ case 'codegen':
143
+ await (0, _codegen.default)({
144
+ root,
145
+ source: _path.default.resolve(root, source),
146
+ output: _path.default.resolve(root, output, 'typescript'),
147
+ report
148
+ });
149
+ break;
150
+ case 'custom':
151
+ await (0, _custom.default)({
152
+ options: targetOptions,
153
+ source: _path.default.resolve(root, source),
154
+ report,
155
+ root
156
+ });
157
+ break;
158
+ default:
159
+ logger.error(`Invalid target ${_kleur.default.blue(targetName)}.`);
160
+ process.exit(1);
161
+ }
162
+ }
163
+ //# sourceMappingURL=build.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build.js","names":["_path","_interopRequireDefault","require","_kleur","logger","_interopRequireWildcard","_commonjs","_module","_typescript","_codegen","_custom","_fsExtra","_loadConfig","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","args","exports","target","type","description","choices","build","argv","root","process","cwd","projectPackagePath","path","resolve","fs","pathExists","Error","result","loadConfig","config","error","$0","exit","options","targets","length","relative","filepath","source","output","exclude","commonjs","some","Array","isArray","module","variants","buildTarget","targetName","targetOptions","undefined","report","grouped","buildCommonJS","buildModule","esm","name","buildTypescript","buildCodegen","customTarget","kleur","blue"],"sources":["../src/build.ts"],"sourcesContent":["import path from 'path';\nimport kleur from 'kleur';\nimport * as logger from './utils/logger';\nimport buildCommonJS from './targets/commonjs';\nimport buildModule from './targets/module';\nimport buildTypescript from './targets/typescript';\nimport buildCodegen from './targets/codegen';\nimport customTarget from './targets/custom';\nimport { type Options, type Target } from './types';\nimport fs from 'fs-extra';\nimport { loadConfig } from './utils/loadConfig';\nimport yargs from 'yargs';\n\nexport const args = {\n target: {\n type: 'string',\n description: 'The target to build',\n choices: ['commonjs', 'module', 'typescript', 'codegen'] satisfies Target[],\n },\n} satisfies Record<'target', yargs.Options>;\n\ntype Argv = {\n $0: string;\n target?: Target;\n};\n\nexport async function build(argv: Argv) {\n const root = process.cwd();\n\n const projectPackagePath = path.resolve(root, 'package.json');\n\n if (!(await fs.pathExists(projectPackagePath))) {\n throw new Error(\n `Couldn't find a 'package.json' file in '${root}'. Are you in a project folder?`\n );\n }\n\n const result = await loadConfig();\n\n if (!result?.config) {\n logger.error(\n `No configuration found. Run '${argv.$0} init' to create one automatically.`\n );\n process.exit(1);\n }\n\n const options: Options = result!.config;\n\n if (!options.targets?.length) {\n logger.error(\n `No targets found in the configuration in '${path.relative(\n root,\n result!.filepath\n )}'.`\n );\n process.exit(1);\n }\n\n const source = options.source;\n\n if (!source) {\n logger.error(\n `No source option found in the configuration in '${path.relative(\n root,\n result!.filepath\n )}'.`\n );\n process.exit(1);\n }\n\n const output = options.output;\n\n if (!output) {\n logger.error(\n `No source option found in the configuration in '${path.relative(\n root,\n result!.filepath\n )}'.`\n );\n process.exit(1);\n }\n\n const exclude = options.exclude ?? '**/{__tests__,__fixtures__,__mocks__}/**';\n\n const commonjs = options.targets?.some((t) =>\n Array.isArray(t) ? t[0] === 'commonjs' : t === 'commonjs'\n );\n\n const module = options.targets?.some((t) =>\n Array.isArray(t) ? t[0] === 'module' : t === 'module'\n );\n\n const variants = {\n commonjs,\n module,\n };\n\n if (argv.target != null) {\n buildTarget({\n root,\n target: argv.target,\n source,\n output,\n exclude,\n options,\n variants,\n });\n } else {\n for (const target of options.targets!) {\n buildTarget({\n root,\n target,\n source,\n output,\n exclude,\n options,\n variants,\n });\n }\n }\n}\n\nasync function buildTarget({\n root,\n target,\n source,\n output,\n exclude,\n options,\n variants,\n}: {\n root: string;\n target: Exclude<Options['targets'], undefined>[number];\n source: string;\n output: string;\n exclude: string;\n options: Options;\n variants: {\n commonjs?: boolean;\n module?: boolean;\n };\n}) {\n const targetName = Array.isArray(target) ? target[0] : target;\n const targetOptions = Array.isArray(target) ? target[1] : undefined;\n\n const report = logger.grouped(targetName);\n\n switch (targetName) {\n case 'commonjs':\n await buildCommonJS({\n root,\n source: path.resolve(root, source),\n output: path.resolve(root, output, 'commonjs'),\n exclude,\n options: targetOptions,\n variants,\n report,\n });\n break;\n case 'module':\n await buildModule({\n root,\n source: path.resolve(root, source),\n output: path.resolve(root, output, 'module'),\n exclude,\n options: targetOptions,\n variants,\n report,\n });\n break;\n case 'typescript':\n {\n const esm =\n options.targets?.some((t) => {\n if (Array.isArray(t)) {\n const [name, options] = t;\n\n if (name === 'module') {\n return options && 'esm' in options && options?.esm;\n }\n }\n\n return false;\n }) ?? false;\n\n await buildTypescript({\n root,\n source: path.resolve(root, source),\n output: path.resolve(root, output, 'typescript'),\n options: targetOptions,\n esm,\n variants,\n report,\n });\n }\n break;\n case 'codegen':\n await buildCodegen({\n root,\n source: path.resolve(root, source),\n output: path.resolve(root, output, 'typescript'),\n report,\n });\n break;\n case 'custom':\n await customTarget({\n options: targetOptions,\n source: path.resolve(root, source),\n report,\n root,\n });\n break;\n default:\n logger.error(`Invalid target ${kleur.blue(targetName)}.`);\n process.exit(1);\n }\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,KAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,MAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,MAAA,GAAAC,uBAAA,CAAAH,OAAA;AACA,IAAAI,SAAA,GAAAL,sBAAA,CAAAC,OAAA;AACA,IAAAK,OAAA,GAAAN,sBAAA,CAAAC,OAAA;AACA,IAAAM,WAAA,GAAAP,sBAAA,CAAAC,OAAA;AACA,IAAAO,QAAA,GAAAR,sBAAA,CAAAC,OAAA;AACA,IAAAQ,OAAA,GAAAT,sBAAA,CAAAC,OAAA;AAEA,IAAAS,QAAA,GAAAV,sBAAA,CAAAC,OAAA;AACA,IAAAU,WAAA,GAAAV,OAAA;AAAgD,SAAAW,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAT,wBAAAS,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAK,OAAA,EAAAL,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAG,GAAA,CAAAN,CAAA,UAAAG,CAAA,CAAAI,GAAA,CAAAP,CAAA,OAAAQ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CAACL,IAAI,EAAEoB,MAAM,CAAC;QAClCC,MAAM,EAAEjB,aAAI,CAACC,OAAO,CAACL,IAAI,EAAEqB,MAAM,EAAE,YAAY,CAAC;QAChDY;MACF,CAAC,CAAC;MACF;IACF,KAAK,QAAQ;MACX,MAAM,IAAAQ,eAAY,EAAC;QACjB1B,OAAO,EAAEgB,aAAa;QACtBX,MAAM,EAAEhB,aAAI,CAACC,OAAO,CAACL,IAAI,EAAEoB,MAAM,CAAC;QAClCa,MAAM;QACNjC;MACF,CAAC,CAAC;MACF;IACF;MACErC,MAAM,CAACiD,KAAK,CAAC,kBAAkB8B,cAAK,CAACC,IAAI,CAACb,UAAU,CAAC,GAAG,CAAC;MACzD7B,OAAO,CAACa,IAAI,CAAC,CAAC,CAAC;EACnB;AACF","ignoreList":[]}
package/lib/index.js CHANGED
@@ -1,21 +1,8 @@
1
1
  "use strict";
2
2
 
3
- var _path = _interopRequireDefault(require("path"));
4
- var _fsExtra = _interopRequireDefault(require("fs-extra"));
5
- var _kleur = _interopRequireDefault(require("kleur"));
6
- var _dedent = _interopRequireDefault(require("dedent"));
7
3
  var _yargs = _interopRequireDefault(require("yargs"));
8
- var _cosmiconfig = require("cosmiconfig");
9
- var _isGitDirty = _interopRequireDefault(require("is-git-dirty"));
10
- var _prompts = _interopRequireDefault(require("./utils/prompts"));
11
- var logger = _interopRequireWildcard(require("./utils/logger"));
12
- var _commonjs = _interopRequireDefault(require("./targets/commonjs"));
13
- var _module = _interopRequireDefault(require("./targets/module"));
14
- var _typescript = _interopRequireDefault(require("./targets/typescript"));
15
- var _codegen = _interopRequireDefault(require("./targets/codegen"));
16
- var _custom = _interopRequireDefault(require("./targets/custom"));
17
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
18
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
4
+ var _build = require("./build");
5
+ var _init = require("./init");
19
6
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
20
7
  const args = {
21
8
  target: {
@@ -24,422 +11,5 @@ const args = {
24
11
  choices: ['commonjs', 'module', 'typescript', 'codegen']
25
12
  }
26
13
  };
27
-
28
- // eslint-disable-next-line import/no-commonjs, @typescript-eslint/no-var-requires
29
- const {
30
- name,
31
- version
32
- } = require('../package.json');
33
- const root = process.cwd();
34
- const explorer = (0, _cosmiconfig.cosmiconfig)(name, {
35
- stopDir: root,
36
- searchPlaces: ['package.json', 'bob.config.mjs', 'bob.config.cjs', 'bob.config.js']
37
- });
38
- const projectPackagePath = _path.default.resolve(root, 'package.json');
39
- const FLOW_PRGAMA_REGEX = /\*?\s*@(flow)\b/m;
40
- _yargs.default.command('init', 'configure the package to use bob', {}, async () => {
41
- if ((0, _isGitDirty.default)()) {
42
- const {
43
- shouldContinue
44
- } = await (0, _prompts.default)({
45
- type: 'confirm',
46
- name: 'shouldContinue',
47
- message: `The working directory is not clean.\n You should commit or stash your changes before configuring bob.\n Continue anyway?`,
48
- initial: false
49
- });
50
- if (!shouldContinue) {
51
- process.exit(0);
52
- }
53
- }
54
- if (!(await _fsExtra.default.pathExists(projectPackagePath))) {
55
- logger.error(`Couldn't find a 'package.json' file in '${root}'.\n Are you in a project folder?`);
56
- process.exit(1);
57
- }
58
- const pkg = JSON.parse(await _fsExtra.default.readFile(projectPackagePath, 'utf-8'));
59
- const result = await explorer.search();
60
- if (result?.config && pkg.devDependencies && name in pkg.devDependencies) {
61
- const {
62
- shouldContinue
63
- } = await (0, _prompts.default)({
64
- type: 'confirm',
65
- name: 'shouldContinue',
66
- message: `The project seems to be already configured with bob.\n Do you want to overwrite the existing configuration?`,
67
- initial: false
68
- });
69
- if (!shouldContinue) {
70
- process.exit(0);
71
- }
72
- }
73
- const {
74
- source
75
- } = await (0, _prompts.default)({
76
- type: 'text',
77
- name: 'source',
78
- message: 'Where are your source files?',
79
- initial: 'src',
80
- validate: input => Boolean(input)
81
- });
82
- let entryFile;
83
- if (await _fsExtra.default.pathExists(_path.default.join(root, source, 'index.js'))) {
84
- entryFile = 'index.js';
85
- } else if (await _fsExtra.default.pathExists(_path.default.join(root, source, 'index.ts'))) {
86
- entryFile = 'index.ts';
87
- } else if (await _fsExtra.default.pathExists(_path.default.join(root, source, 'index.tsx'))) {
88
- entryFile = 'index.tsx';
89
- }
90
- if (!entryFile) {
91
- logger.error(`Couldn't find a 'index.js'. 'index.ts' or 'index.tsx' file under '${source}'.\n Please re-run the CLI after creating it.`);
92
- process.exit(1);
93
- }
94
- pkg.devDependencies = Object.fromEntries([...Object.entries(pkg.devDependencies || {}), [name, `^${version}`]].sort(([a], [b]) => a.localeCompare(b)));
95
- const questions = [{
96
- type: 'text',
97
- name: 'output',
98
- message: 'Where do you want to generate the output files?',
99
- initial: 'lib',
100
- validate: input => Boolean(input)
101
- }, {
102
- type: 'multiselect',
103
- name: 'targets',
104
- message: 'Which targets do you want to build?',
105
- choices: [{
106
- title: 'commonjs - for running in Node (tests, SSR etc.)',
107
- value: 'commonjs',
108
- selected: true
109
- }, {
110
- title: 'module - for bundlers (metro, webpack etc.)',
111
- value: 'module',
112
- selected: true
113
- }, {
114
- title: 'typescript - declaration files for typechecking',
115
- value: 'typescript',
116
- selected: /\.tsx?$/.test(entryFile)
117
- }],
118
- validate: input => Boolean(input.length)
119
- }];
120
- if (entryFile.endsWith('.js') && FLOW_PRGAMA_REGEX.test(await _fsExtra.default.readFile(_path.default.join(root, source, entryFile), 'utf-8'))) {
121
- questions.push({
122
- type: 'confirm',
123
- name: 'flow',
124
- message: 'Do you want to publish definitions for flow?',
125
- initial: Object.keys(pkg.devDependencies || {}).includes('flow-bin')
126
- });
127
- }
128
- const {
129
- output,
130
- targets,
131
- flow
132
- } = await (0, _prompts.default)(questions);
133
- const target = targets[0] === 'commonjs' || targets[0] === 'module' ? targets[0] : undefined;
134
- const entries = {
135
- source: `./${_path.default.join(source, entryFile)}`
136
- };
137
- let esm = false;
138
- if (targets.includes('module')) {
139
- esm = true;
140
- if (targets.includes('commonjs')) {
141
- entries.main = `./${_path.default.join(output, 'commonjs', 'index.js')}`;
142
- }
143
- entries.module = `./${_path.default.join(output, 'module', 'index.js')}`;
144
- } else if (targets.includes('commonjs')) {
145
- entries.main = `./${_path.default.join(output, 'commonjs', 'index.js')}`;
146
- } else {
147
- entries.main = entries.source;
148
- }
149
- const types = {};
150
- if (targets.includes('typescript')) {
151
- types.require = `./${_path.default.join(output, 'typescript', 'commonjs', source, 'index.d.ts')}`;
152
- types.import = `./${_path.default.join(output, 'typescript', 'module', source, 'index.d.ts')}`;
153
- entries.types = types.require;
154
- if (!(await _fsExtra.default.pathExists(_path.default.join(root, 'tsconfig.json')))) {
155
- const {
156
- tsconfig
157
- } = await (0, _prompts.default)({
158
- type: 'confirm',
159
- name: 'tsconfig',
160
- message: `You have enabled 'typescript' compilation, but we couldn't find a 'tsconfig.json' in project root.\n Generate one?`,
161
- initial: true
162
- });
163
- if (tsconfig) {
164
- await _fsExtra.default.writeJSON(_path.default.join(root, 'tsconfig.json'), {
165
- compilerOptions: {
166
- rootDir: '.',
167
- allowUnreachableCode: false,
168
- allowUnusedLabels: false,
169
- esModuleInterop: true,
170
- forceConsistentCasingInFileNames: true,
171
- jsx: 'react-jsx',
172
- lib: ['ESNext'],
173
- module: 'ESNext',
174
- moduleResolution: 'Bundler',
175
- noFallthroughCasesInSwitch: true,
176
- noImplicitReturns: true,
177
- noImplicitUseStrict: false,
178
- noStrictGenericChecks: false,
179
- noUncheckedIndexedAccess: true,
180
- noUnusedLocals: true,
181
- noUnusedParameters: true,
182
- resolveJsonModule: true,
183
- skipLibCheck: true,
184
- strict: true,
185
- target: 'ESNext',
186
- verbatimModuleSyntax: true
187
- }
188
- }, {
189
- spaces: 2
190
- });
191
- }
192
- }
193
- }
194
- const prepare = 'bob build';
195
- const files = [source, output, '!**/__tests__', '!**/__fixtures__', '!**/__mocks__'];
196
- for (const key in entries) {
197
- const entry = entries[key];
198
- if (pkg[key] && pkg[key] !== entry) {
199
- const {
200
- replace
201
- } = await (0, _prompts.default)({
202
- type: 'confirm',
203
- name: 'replace',
204
- message: `Your package.json has the '${key}' field set to '${pkg[key]}'.\n Do you want to replace it with '${entry}'?`,
205
- initial: true
206
- });
207
- if (replace) {
208
- pkg[key] = entry;
209
- }
210
- } else {
211
- pkg[key] = entry;
212
- }
213
- }
214
- if (esm) {
215
- let replace = false;
216
- const exportsField = {
217
- '.': {
218
- import: {
219
- ...(types.import ? {
220
- types: types.import
221
- } : null),
222
- ...(entries.module ? {
223
- default: entries.module
224
- } : null)
225
- },
226
- require: {
227
- ...(types.require ? {
228
- types: types.require
229
- } : null),
230
- ...(entries.main ? {
231
- default: entries.main
232
- } : null)
233
- }
234
- }
235
- };
236
- if (pkg.codegenConfig && !pkg.codegenConfig.includesGeneratedCode) {
237
- // @ts-expect-error The exports is not strictly types therefore it doesn't know about the package.json property
238
- exportsField['./package.json'] = './package.json';
239
- }
240
- if (pkg.exports && JSON.stringify(pkg.exports) !== JSON.stringify(exportsField)) {
241
- replace = (await (0, _prompts.default)({
242
- type: 'confirm',
243
- name: 'replace',
244
- message: `Your package.json has 'exports' field set.\n Do you want to replace it?`,
245
- initial: true
246
- })).replace;
247
- } else {
248
- replace = true;
249
- }
250
- if (replace) {
251
- pkg.exports = exportsField;
252
- }
253
- }
254
- if (pkg['react-native'] && (pkg['react-native'].startsWith(source) || pkg['react-native'].startsWith(`./${source}`))) {
255
- const {
256
- remove
257
- } = await (0, _prompts.default)({
258
- type: 'confirm',
259
- name: 'remove',
260
- message: `Your package.json has the 'react-native' field pointing to source code.\n This can cause problems when customizing babel configuration.\n Do you want to remove it?`,
261
- initial: true
262
- });
263
- if (remove) {
264
- delete pkg['react-native'];
265
- }
266
- }
267
- if (pkg.scripts?.prepare && pkg.scripts.prepare !== prepare) {
268
- const {
269
- replace
270
- } = await (0, _prompts.default)({
271
- type: 'confirm',
272
- name: 'replace',
273
- message: `Your package.json has the 'scripts.prepare' field set to '${pkg.scripts.prepare}'.\n Do you want to replace it with '${prepare}'?`,
274
- initial: true
275
- });
276
- if (replace) {
277
- pkg.scripts.prepare = prepare;
278
- }
279
- } else {
280
- pkg.scripts = pkg.scripts || {};
281
- pkg.scripts.prepare = prepare;
282
- }
283
- if (pkg.files) {
284
- const pkgFiles = pkg.files;
285
- if (files?.some(file => !pkgFiles.includes(file))) {
286
- const {
287
- update
288
- } = await (0, _prompts.default)({
289
- type: 'confirm',
290
- name: 'update',
291
- message: `Your package.json already has a 'files' field.\n Do you want to update it?`,
292
- initial: true
293
- });
294
- if (update) {
295
- pkg.files = [...files, ...pkg.files.filter(file => !files.includes(file))];
296
- }
297
- }
298
- } else {
299
- pkg.files = files;
300
- }
301
- pkg[name] = {
302
- source,
303
- output,
304
- targets: targets.map(t => {
305
- if (t === target && flow) {
306
- return [t, {
307
- copyFlow: true
308
- }];
309
- }
310
- if (t === 'commonjs' || t === 'module' || t === 'typescript') {
311
- return [t, {
312
- esm
313
- }];
314
- }
315
- return t;
316
- })
317
- };
318
- if (pkg.jest) {
319
- const entry = `<rootDir>/${output}/`;
320
- if (pkg.jest.modulePathIgnorePatterns) {
321
- const {
322
- modulePathIgnorePatterns
323
- } = pkg.jest;
324
- if (!modulePathIgnorePatterns.includes(entry)) {
325
- modulePathIgnorePatterns.push(entry);
326
- }
327
- } else {
328
- pkg.jest.modulePathIgnorePatterns = [entry];
329
- }
330
- }
331
- pkg.eslintIgnore = pkg.eslintIgnore || ['node_modules/'];
332
- if (!pkg.eslintIgnore.includes(`${output}/`)) {
333
- pkg.eslintIgnore.push(`${output}/`);
334
- }
335
- await _fsExtra.default.writeJSON(projectPackagePath, pkg, {
336
- spaces: 2
337
- });
338
- const ignorefiles = [_path.default.join(root, '.gitignore'), _path.default.join(root, '.eslintignore')];
339
- for (const ignorefile of ignorefiles) {
340
- if (await _fsExtra.default.pathExists(ignorefile)) {
341
- const content = await _fsExtra.default.readFile(ignorefile, 'utf-8');
342
- if (!content.split('\n').includes(`${output}/`)) {
343
- await _fsExtra.default.writeFile(ignorefile, `${content}\n# generated by bob\n${output}/\n`);
344
- }
345
- }
346
- }
347
- const packageManager = (await _fsExtra.default.pathExists(_path.default.join(root, 'yarn.lock'))) ? 'yarn' : 'npm';
348
- console.log((0, _dedent.default)(`
349
- Project ${_kleur.default.yellow(pkg.name)} configured successfully!
350
-
351
- ${_kleur.default.magenta(`${_kleur.default.bold('Perform last steps')} by running`)}${_kleur.default.gray(':')}
352
-
353
- ${_kleur.default.gray('$')} ${packageManager} install
354
-
355
- ${_kleur.default.yellow('Good luck!')}
356
- `));
357
- }).command('build', 'build files for publishing', args, async argv => {
358
- if (!(await _fsExtra.default.pathExists(projectPackagePath))) {
359
- throw new Error(`Couldn't find a 'package.json' file in '${root}'. Are you in a project folder?`);
360
- }
361
- const result = await explorer.search();
362
- if (!result?.config) {
363
- logger.error(`No configuration found. Run '${argv.$0} init' to create one automatically.`);
364
- process.exit(1);
365
- }
366
- const options = result.config;
367
- if (!options.targets?.length) {
368
- logger.error(`No targets found in the configuration in '${_path.default.relative(root, result.filepath)}'.`);
369
- process.exit(1);
370
- }
371
- const source = options.source;
372
- if (!source) {
373
- logger.error(`No source option found in the configuration in '${_path.default.relative(root, result.filepath)}'.`);
374
- process.exit(1);
375
- }
376
- const output = options.output;
377
- if (!output) {
378
- logger.error(`No source option found in the configuration in '${_path.default.relative(root, result.filepath)}'.`);
379
- process.exit(1);
380
- }
381
- const exclude = options.exclude ?? '**/{__tests__,__fixtures__,__mocks__}/**';
382
- if (argv.target != null) {
383
- buildTarget(argv.target, source, output, exclude);
384
- } else {
385
- for (const target of options.targets) {
386
- buildTarget(target, source, output, exclude);
387
- }
388
- }
389
- }).demandCommand().recommendCommands().strict().argv;
390
- async function buildTarget(target, source, output, exclude) {
391
- const targetName = Array.isArray(target) ? target[0] : target;
392
- const targetOptions = Array.isArray(target) ? target[1] : undefined;
393
- const report = logger.grouped(targetName);
394
- switch (targetName) {
395
- case 'commonjs':
396
- await (0, _commonjs.default)({
397
- root,
398
- source: _path.default.resolve(root, source),
399
- output: _path.default.resolve(root, output, 'commonjs'),
400
- exclude,
401
- options: targetOptions,
402
- report
403
- });
404
- break;
405
- case 'module':
406
- await (0, _module.default)({
407
- root,
408
- source: _path.default.resolve(root, source),
409
- output: _path.default.resolve(root, output, 'module'),
410
- exclude,
411
- options: targetOptions,
412
- report
413
- });
414
- break;
415
- case 'typescript':
416
- await (0, _typescript.default)({
417
- root,
418
- source: _path.default.resolve(root, source),
419
- output: _path.default.resolve(root, output, 'typescript'),
420
- options: targetOptions,
421
- report
422
- });
423
- break;
424
- case 'codegen':
425
- await (0, _codegen.default)({
426
- root,
427
- source: _path.default.resolve(root, source),
428
- output: _path.default.resolve(root, output, 'typescript'),
429
- report
430
- });
431
- break;
432
- case 'custom':
433
- await (0, _custom.default)({
434
- options: targetOptions,
435
- source: _path.default.resolve(root, source),
436
- report,
437
- root
438
- });
439
- break;
440
- default:
441
- logger.error(`Invalid target ${_kleur.default.blue(targetName)}.`);
442
- process.exit(1);
443
- }
444
- }
14
+ _yargs.default.command('init', 'configure the package to use bob', {}, _init.init).command('build', 'build files for publishing', args, _build.build).demandCommand().recommendCommands().strict().argv;
445
15
  //# sourceMappingURL=index.js.map