react-native-builder-bob 0.23.2 → 0.25.0-next.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.
Files changed (38) hide show
  1. package/babel-preset.js +50 -0
  2. package/lib/__fixtures__/project/code/$alias-input.js +8 -0
  3. package/lib/__fixtures__/project/code/$alias-input.js.map +1 -0
  4. package/lib/__fixtures__/project/code/$alias-output.js +8 -0
  5. package/lib/__fixtures__/project/code/$alias-output.js.map +1 -0
  6. package/lib/__fixtures__/project/code/$exports-input.js +64 -0
  7. package/lib/__fixtures__/project/code/$exports-input.js.map +1 -0
  8. package/lib/__fixtures__/project/code/$exports-output.js +64 -0
  9. package/lib/__fixtures__/project/code/$exports-output.js.map +1 -0
  10. package/lib/__fixtures__/project/code/$imports-input.js +4 -0
  11. package/lib/__fixtures__/project/code/$imports-input.js.map +1 -0
  12. package/lib/__fixtures__/project/code/$imports-output.js +4 -0
  13. package/lib/__fixtures__/project/code/$imports-output.js.map +1 -0
  14. package/lib/__fixtures__/project/code/a.js +2 -0
  15. package/lib/__fixtures__/project/code/a.js.map +1 -0
  16. package/lib/__fixtures__/project/code/b.js +2 -0
  17. package/lib/__fixtures__/project/code/b.js.map +1 -0
  18. package/lib/__fixtures__/project/code/e.story.js +2 -0
  19. package/lib/__fixtures__/project/code/e.story.js.map +1 -0
  20. package/lib/__fixtures__/project/f.js +2 -0
  21. package/lib/__fixtures__/project/f.js.map +1 -0
  22. package/lib/__fixtures__/project/index.js +2 -0
  23. package/lib/__fixtures__/project/index.js.map +1 -0
  24. package/lib/__tests__/index.test.js +37 -0
  25. package/lib/__tests__/index.test.js.map +1 -0
  26. package/lib/babel.js +103 -0
  27. package/lib/babel.js.map +1 -0
  28. package/lib/index.js +59 -18
  29. package/lib/index.js.map +1 -1
  30. package/lib/targets/commonjs.js +1 -2
  31. package/lib/targets/commonjs.js.map +1 -1
  32. package/lib/targets/module.js +1 -2
  33. package/lib/targets/module.js.map +1 -1
  34. package/lib/targets/typescript.js +25 -10
  35. package/lib/targets/typescript.js.map +1 -1
  36. package/lib/utils/compile.js +40 -25
  37. package/lib/utils/compile.js.map +1 -1
  38. package/package.json +14 -5
@@ -0,0 +1,50 @@
1
+ /* eslint-disable import/no-commonjs */
2
+
3
+ const browserslist = require('browserslist');
4
+
5
+ module.exports = function (api, options, cwd) {
6
+ const cjs = options.modules === 'commonjs';
7
+
8
+ return {
9
+ presets: [
10
+ [
11
+ require.resolve('@babel/preset-env'),
12
+ {
13
+ targets: browserslist.findConfig(cwd) || {
14
+ browsers: [
15
+ '>1%',
16
+ 'last 2 chrome versions',
17
+ 'last 2 edge versions',
18
+ 'last 2 firefox versions',
19
+ 'last 2 safari versions',
20
+ 'not dead',
21
+ 'not ie <= 11',
22
+ 'not op_mini all',
23
+ 'not android <= 4.4',
24
+ 'not samsung <= 4',
25
+ ],
26
+ node: '18',
27
+ },
28
+ useBuiltIns: false,
29
+ modules: cjs ? 'commonjs' : false,
30
+ },
31
+ ],
32
+ [
33
+ require.resolve('@babel/preset-react'),
34
+ {
35
+ runtime: 'automatic',
36
+ },
37
+ ],
38
+ require.resolve('@babel/preset-typescript'),
39
+ require.resolve('@babel/preset-flow'),
40
+ ],
41
+ plugins: [
42
+ [
43
+ require.resolve('./lib/babel'),
44
+ {
45
+ extension: cjs ? 'cjs' : 'mjs',
46
+ },
47
+ ],
48
+ ],
49
+ };
50
+ };
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+
3
+ require("@");
4
+ require("@something");
5
+ require("./@");
6
+ require("file");
7
+ require("something/somefile");
8
+ //# sourceMappingURL=$alias-input.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"$alias-input.js","names":["require"],"sources":["../../../../src/__fixtures__/project/code/$alias-input.ts"],"sourcesContent":["import \"@\";\nimport f from \"@/f\";\nimport \"@something\";\nimport \"./@\";\nimport \"file\";\nimport { something } from \"something\";\nimport \"something/somefile\";\n"],"mappings":";;AAAAA,OAAA;AAEAA,OAAA;AACAA,OAAA;AACAA,OAAA;AAEAA,OAAA"}
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+
3
+ require("..");
4
+ require("@something");
5
+ require("./@");
6
+ require("../f");
7
+ require("another/somefile");
8
+ //# sourceMappingURL=$alias-output.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"$alias-output.js","names":["require"],"sources":["../../../../src/__fixtures__/project/code/$alias-output.ts"],"sourcesContent":["import \"..\";\nimport f from \"../f\";\nimport \"@something\";\nimport \"./@\";\nimport \"../f\";\nimport { something } from \"another\";\nimport \"another/somefile\";\n"],"mappings":";;AAAAA,OAAA;AAEAA,OAAA;AACAA,OAAA;AACAA,OAAA;AAEAA,OAAA"}
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _exportNames = {
7
+ foo: true,
8
+ bar: true,
9
+ a: true,
10
+ b: true,
11
+ c: true,
12
+ d: true,
13
+ e: true,
14
+ f: true,
15
+ pac: true,
16
+ pak: true,
17
+ pax: true,
18
+ a1: true
19
+ };
20
+ exports.a = void 0;
21
+ Object.defineProperty(exports, "a1", {
22
+ enumerable: true,
23
+ get: function () {
24
+ return _a3.a;
25
+ }
26
+ });
27
+ exports.pax = exports.pak = exports.pac = exports.foo = exports.f = exports.e = exports.d = exports.c = exports.bar = exports.b = void 0;
28
+ var _a = _interopRequireWildcard(require("a"));
29
+ exports.a = _a;
30
+ var _b = _interopRequireWildcard(require("./b"));
31
+ exports.b = _b;
32
+ Object.keys(_b).forEach(function (key) {
33
+ if (key === "default" || key === "__esModule") return;
34
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
35
+ if (key in exports && exports[key] === _b[key]) return;
36
+ Object.defineProperty(exports, key, {
37
+ enumerable: true,
38
+ get: function () {
39
+ return _b[key];
40
+ }
41
+ });
42
+ });
43
+ var _c = _interopRequireWildcard(require("./c"));
44
+ exports.c = _c;
45
+ var _d = _interopRequireWildcard(require("./d"));
46
+ exports.d = _d;
47
+ var _e = _interopRequireWildcard(require("./e.story"));
48
+ exports.e = _e;
49
+ var _f = _interopRequireWildcard(require("../f"));
50
+ exports.f = _f;
51
+ var _pac = _interopRequireWildcard(require(".."));
52
+ exports.pac = _pac;
53
+ var _pak = _interopRequireWildcard(require("../"));
54
+ exports.pak = _pak;
55
+ var _pax = _interopRequireWildcard(require("../index"));
56
+ exports.pax = _pax;
57
+ var _a3 = require("./a");
58
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
59
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
60
+ const foo = "foo";
61
+ exports.foo = foo;
62
+ const bar = "bar";
63
+ exports.bar = bar;
64
+ //# sourceMappingURL=$exports-input.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"$exports-input.js","names":["_b","_interopRequireWildcard","require","exports","b","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","defineProperty","enumerable","get","_c","c","_d","d","_e","e","_f","f","_pac","pac","_pak","pak","_pax","pax","_a3","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","newObj","hasPropertyDescriptor","getOwnPropertyDescriptor","desc","set","foo","bar"],"sources":["../../../../src/__fixtures__/project/code/$exports-input.ts"],"sourcesContent":["export * as a from \"a\";\nexport * as b from \"./b\";\nexport * as c from \"./c\";\nexport * as d from \"./d\";\nexport * as e from \"./e.story\";\nexport * as f from \"../f\";\nexport * as pac from \"..\";\nexport * as pak from \"../\";\nexport * as pax from \"../index\";\n\nexport { a as a1 } from \"./a\";\nexport * from \"./b\";\n\nexport type { A } from \"./a\";\n\nexport const foo = \"foo\";\n\nconst bar = \"bar\";\n\nexport { bar };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAWA,IAAAA,EAAA,GAAAC,uBAAA,CAAAC,OAAA;AAAoBC,OAAA,CAAAC,CAAA,GAAAJ,EAAA;AAApBK,MAAA,CAAAC,IAAA,CAAAN,EAAA,EAAAO,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAL,OAAA,IAAAA,OAAA,CAAAK,GAAA,MAAAR,EAAA,CAAAQ,GAAA;EAAAH,MAAA,CAAAQ,cAAA,CAAAV,OAAA,EAAAK,GAAA;IAAAM,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAf,EAAA,CAAAQ,GAAA;IAAA;EAAA;AAAA;AAAoB,IAAAQ,EAAA,GAAAf,uBAAA,CAAAC,OAAA;AAAAC,OAAA,CAAAc,CAAA,GAAAD,EAAA;AAAA,IAAAE,EAAA,GAAAjB,uBAAA,CAAAC,OAAA;AAAAC,OAAA,CAAAgB,CAAA,GAAAD,EAAA;AAAA,IAAAE,EAAA,GAAAnB,uBAAA,CAAAC,OAAA;AAAAC,OAAA,CAAAkB,CAAA,GAAAD,EAAA;AAAA,IAAAE,EAAA,GAAArB,uBAAA,CA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C,MAAA,CAAAQ,cAAA,CAAA4B,MAAA,EAAAjC,GAAA,EAAAoC,IAAA,YAAAH,MAAA,CAAAjC,GAAA,IAAA4B,GAAA,CAAA5B,GAAA,SAAAiC,MAAA,CAAAH,OAAA,GAAAF,GAAA,MAAAG,KAAA,IAAAA,KAAA,CAAAM,GAAA,CAAAT,GAAA,EAAAK,MAAA,YAAAA,MAAA;AAKvB,MAAMK,GAAG,GAAG,KAAK;AAAC3C,OAAA,CAAA2C,GAAA,GAAAA,GAAA;AAEzB,MAAMC,GAAG,GAAG,KAAK;AAAC5C,OAAA,CAAA4C,GAAA,GAAAA,GAAA"}
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _exportNames = {
7
+ foo: true,
8
+ bar: true,
9
+ a: true,
10
+ b: true,
11
+ c: true,
12
+ d: true,
13
+ e: true,
14
+ f: true,
15
+ pac: true,
16
+ pak: true,
17
+ pax: true,
18
+ a1: true
19
+ };
20
+ exports.a = void 0;
21
+ Object.defineProperty(exports, "a1", {
22
+ enumerable: true,
23
+ get: function () {
24
+ return _a3.a;
25
+ }
26
+ });
27
+ exports.pax = exports.pak = exports.pac = exports.foo = exports.f = exports.e = exports.d = exports.c = exports.bar = exports.b = void 0;
28
+ var _a = _interopRequireWildcard(require("a"));
29
+ exports.a = _a;
30
+ var _b = _interopRequireWildcard(require("./b.mjs"));
31
+ exports.b = _b;
32
+ Object.keys(_b).forEach(function (key) {
33
+ if (key === "default" || key === "__esModule") return;
34
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
35
+ if (key in exports && exports[key] === _b[key]) return;
36
+ Object.defineProperty(exports, key, {
37
+ enumerable: true,
38
+ get: function () {
39
+ return _b[key];
40
+ }
41
+ });
42
+ });
43
+ var _c = _interopRequireWildcard(require("./c.mjs"));
44
+ exports.c = _c;
45
+ var _d = _interopRequireWildcard(require("./d"));
46
+ exports.d = _d;
47
+ var _e = _interopRequireWildcard(require("./e.story.mjs"));
48
+ exports.e = _e;
49
+ var _f = _interopRequireWildcard(require("../f.mjs"));
50
+ exports.f = _f;
51
+ var _pac = _interopRequireWildcard(require("../index.mjs"));
52
+ var _pak = _pac;
53
+ var _pax = _pac;
54
+ exports.pac = _pac;
55
+ exports.pak = _pac;
56
+ exports.pax = _pac;
57
+ var _a3 = require("./a.mjs");
58
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
59
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
60
+ const foo = "foo";
61
+ exports.foo = foo;
62
+ const bar = "bar";
63
+ exports.bar = bar;
64
+ //# sourceMappingURL=$exports-output.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"$exports-output.js","names":["_b","_interopRequireWildcard","require","exports","b","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","defineProperty","enumerable","get","_c","c","_d","d","_e","e","_f","f","_pac","_pak","_pax","pac","pak","pax","_a3","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","newObj","hasPropertyDescriptor","getOwnPropertyDescriptor","desc","set","foo","bar"],"sources":["../../../../src/__fixtures__/project/code/$exports-output.ts"],"sourcesContent":["export * as a from \"a\";\nexport * as b from \"./b.mjs\";\nexport * as c from \"./c.mjs\";\nexport * as d from \"./d\";\nexport * as e from \"./e.story.mjs\";\nexport * as f from \"../f.mjs\";\nexport * as pac from \"../index.mjs\";\nexport * as pak from \"../index.mjs\";\nexport * as pax from \"../index.mjs\";\nexport { a as a1 } from \"./a.mjs\";\nexport * from \"./b.mjs\";\nexport type { A } from \"./a\";\nexport const foo = \"foo\";\nconst bar = \"bar\";\nexport { bar };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUA,IAAAA,EAAA,GAAAC,uBAAA,CAAAC,OAAA;AAAwBC,OAAA,CAAAC,CAAA,GAAAJ,EAAA;AAAxBK,MAAA,CAAAC,IAAA,CAAAN,EAAA,EAAAO,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAL,OAAA,IAAAA,OAAA,CAAAK,GAAA,MAAAR,EAAA,CAAAQ,GAAA;EAAAH,MAAA,CAAAQ,cAAA,CAAAV,OAAA,EAAAK,GAAA;IAAAM,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAf,EAAA,CAAAQ,GAAA;IAAA;EAAA;AAAA;AAAwB,IAAAQ,EAAA,GAAAf,uBAAA,CAAAC,OAAA;AAAAC,OAAA,CAAAc,CAAA,GAAAD,EAAA;AAAA,IAAAE,EAAA,GAAAjB,uBAAA,CAAAC,OAAA;AAAAC,OAAA,CAAAgB,CAAA,GAAAD,EAAA;AAAA,IAAAE,EAAA,GAAAnB,uBAAA,CAAAC,OAAA;AAAAC,OAAA,CAAAkB,CAAA,GAAAD,EAAA;AAAA,IAAAE,EAAA,GAAArB,uBAAA,CAAAC,OAAA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AAAjC,GAAA,EAAAoC,IAAA,YAAAH,MAAA,CAAAjC,GAAA,IAAA4B,GAAA,CAAA5B,GAAA,SAAAiC,MAAA,CAAAH,OAAA,GAAAF,GAAA,MAAAG,KAAA,IAAAA,KAAA,CAAAM,GAAA,CAAAT,GAAA,EAAAK,MAAA,YAAAA,MAAA;AAG3B,MAAMK,GAAG,GAAG,KAAK;AAAC3C,OAAA,CAAA2C,GAAA,GAAAA,GAAA;AACzB,MAAMC,GAAG,GAAG,KAAK;AAAC5C,OAAA,CAAA4C,GAAA,GAAAA,GAAA"}
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+
3
+ require("./a");
4
+ //# sourceMappingURL=$imports-input.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"$imports-input.js","names":["require"],"sources":["../../../../src/__fixtures__/project/code/$imports-input.ts"],"sourcesContent":["import \"./a\";\nimport a from \"a\";\nimport b from \"./b\";\nimport c from \"./c\";\nimport d from \"./d\";\nimport e from \"./e.story\";\nimport f from \"../f\";\nimport pac from \"..\";\nimport pak from \"../\";\nimport pax from \"../index\";\n\nimport { a as a1 } from \"./a\";\nimport * as b1 from \"./b\";\nimport something, { c as c1 } from \"./c\";\n\nimport type { A } from \"./a\";\n"],"mappings":";;AAAAA,OAAA"}
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+
3
+ require("./a.mjs");
4
+ //# sourceMappingURL=$imports-output.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"$imports-output.js","names":["require"],"sources":["../../../../src/__fixtures__/project/code/$imports-output.ts"],"sourcesContent":["import \"./a.mjs\";\nimport a from \"a\";\nimport b from \"./b.mjs\";\nimport c from \"./c.mjs\";\nimport d from \"./d\";\nimport e from \"./e.story.mjs\";\nimport f from \"../f.mjs\";\nimport pac from \"../index.mjs\";\nimport pak from \"../index.mjs\";\nimport pax from \"../index.mjs\";\nimport { a as a1 } from \"./a.mjs\";\nimport * as b1 from \"./b.mjs\";\nimport something, { c as c1 } from \"./c.mjs\";\nimport type { A } from \"./a\";\n"],"mappings":";;AAAAA,OAAA"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=a.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"a.js","names":[],"sources":["../../../../src/__fixtures__/project/code/a.ts"],"sourcesContent":[""],"mappings":""}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=b.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"b.js","names":[],"sources":["../../../../src/__fixtures__/project/code/b.ts"],"sourcesContent":[""],"mappings":""}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=e.story.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"e.story.js","names":[],"sources":["../../../../src/__fixtures__/project/code/e.story.ts"],"sourcesContent":[""],"mappings":""}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=f.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"f.js","names":[],"sources":["../../../src/__fixtures__/project/f.ts"],"sourcesContent":[""],"mappings":""}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../src/__fixtures__/project/index.ts"],"sourcesContent":[""],"mappings":""}
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+
3
+ var _globals = require("@jest/globals");
4
+ var _core = require("@babel/core");
5
+ var _nodeFs = _interopRequireDefault(require("node:fs"));
6
+ var _nodePath = _interopRequireDefault(require("node:path"));
7
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
8
+ _globals.it.each(['imports', 'exports'])(`adds .js extension to %s`, async name => {
9
+ const filepath = _nodePath.default.resolve(__dirname, `../__fixtures__/project/code/$${name}-input.ts`);
10
+ const result = await (0, _core.transformFileAsync)(filepath, {
11
+ configFile: false,
12
+ babelrc: false,
13
+ plugins: ['@babel/plugin-syntax-typescript', [require.resolve('../babel.ts'), {
14
+ extension: 'mjs'
15
+ }]]
16
+ });
17
+ const expected = await _nodeFs.default.promises.readFile(_nodePath.default.resolve(__dirname, `../__fixtures__/project/code/$${name}-output.ts`), 'utf8');
18
+ (0, _globals.expect)(result?.code).toEqual(expected.trim());
19
+ });
20
+ (0, _globals.it)('replaces alias imports', async () => {
21
+ const filepath = _nodePath.default.resolve(__dirname, `../__fixtures__/project/code/$alias-input.ts`);
22
+ const result = await (0, _core.transformFileAsync)(filepath, {
23
+ cwd: __dirname,
24
+ configFile: false,
25
+ babelrc: false,
26
+ plugins: ['@babel/plugin-syntax-typescript', [require.resolve('../babel.ts'), {
27
+ alias: {
28
+ '@': '../__fixtures__/project',
29
+ 'file': '../__fixtures__/project/f',
30
+ 'something': 'another'
31
+ }
32
+ }]]
33
+ });
34
+ const expected = await _nodeFs.default.promises.readFile(_nodePath.default.resolve(__dirname, `../__fixtures__/project/code/$alias-output.ts`), 'utf8');
35
+ (0, _globals.expect)(result?.code).toEqual(expected.trim());
36
+ });
37
+ //# sourceMappingURL=index.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.test.js","names":["_globals","require","_core","_nodeFs","_interopRequireDefault","_nodePath","obj","__esModule","default","it","each","name","filepath","path","resolve","__dirname","result","transformFileAsync","configFile","babelrc","plugins","extension","expected","fs","promises","readFile","expect","code","toEqual","trim","cwd","alias"],"sources":["../../src/__tests__/index.test.ts"],"sourcesContent":["import { expect, it } from '@jest/globals';\nimport { transformFileAsync } from '@babel/core';\nimport fs from 'node:fs';\nimport path from 'node:path';\n\nit.each(['imports', 'exports'])(`adds .js extension to %s`, async (name) => {\n const filepath = path.resolve(\n __dirname,\n `../__fixtures__/project/code/$${name}-input.ts`\n );\n\n const result = await transformFileAsync(filepath, {\n configFile: false,\n babelrc: false,\n plugins: [\n '@babel/plugin-syntax-typescript',\n [require.resolve('../babel.ts'), { extension: 'mjs' }],\n ],\n });\n\n const expected = await fs.promises.readFile(\n path.resolve(__dirname, `../__fixtures__/project/code/$${name}-output.ts`),\n 'utf8'\n );\n\n expect(result?.code).toEqual(expected.trim());\n});\n\nit('replaces alias imports', async () => {\n const filepath = path.resolve(\n __dirname,\n `../__fixtures__/project/code/$alias-input.ts`\n );\n\n const result = await transformFileAsync(filepath, {\n cwd: __dirname,\n configFile: false,\n babelrc: false,\n plugins: [\n '@babel/plugin-syntax-typescript',\n [\n require.resolve('../babel.ts'),\n {\n alias: {\n '@': '../__fixtures__/project',\n 'file': '../__fixtures__/project/f',\n 'something': 'another',\n },\n },\n ],\n ],\n });\n\n const expected = await fs.promises.readFile(\n path.resolve(__dirname, `../__fixtures__/project/code/$alias-output.ts`),\n 'utf8'\n );\n\n expect(result?.code).toEqual(expected.trim());\n});\n"],"mappings":";;AAAA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAC,sBAAA,CAAAH,OAAA;AACA,IAAAI,SAAA,GAAAD,sBAAA,CAAAH,OAAA;AAA6B,SAAAG,uBAAAE,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAE7BG,WAAE,CAACC,IAAI,CAAC,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC,CAAE,0BAAyB,EAAE,MAAOC,IAAI,IAAK;EAC1E,MAAMC,QAAQ,GAAGC,iBAAI,CAACC,OAAO,CAC3BC,SAAS,EACR,iCAAgCJ,IAAK,WACxC,CAAC;EAED,MAAMK,MAAM,GAAG,MAAM,IAAAC,wBAAkB,EAACL,QAAQ,EAAE;IAChDM,UAAU,EAAE,KAAK;IACjBC,OAAO,EAAE,KAAK;IACdC,OAAO,EAAE,CACP,iCAAiC,EACjC,CAACnB,OAAO,CAACa,OAAO,CAAC,aAAa,CAAC,EAAE;MAAEO,SAAS,EAAE;IAAM,CAAC,CAAC;EAE1D,CAAC,CAAC;EAEF,MAAMC,QAAQ,GAAG,MAAMC,eAAE,CAACC,QAAQ,CAACC,QAAQ,CACzCZ,iBAAI,CAACC,OAAO,CAACC,SAAS,EAAG,iCAAgCJ,IAAK,YAAW,CAAC,EAC1E,MACF,CAAC;EAED,IAAAe,eAAM,EAACV,MAAM,EAAEW,IAAI,CAAC,CAACC,OAAO,CAACN,QAAQ,CAACO,IAAI,CAAC,CAAC,CAAC;AAC/C,CAAC,CAAC;AAEF,IAAApB,WAAE,EAAC,wBAAwB,EAAE,YAAY;EACvC,MAAMG,QAAQ,GAAGC,iBAAI,CAACC,OAAO,CAC3BC,SAAS,EACR,8CACH,CAAC;EAED,MAAMC,MAAM,GAAG,MAAM,IAAAC,wBAAkB,EAACL,QAAQ,EAAE;IAChDkB,GAAG,EAAEf,SAAS;IACdG,UAAU,EAAE,KAAK;IACjBC,OAAO,EAAE,KAAK;IACdC,OAAO,EAAE,CACP,iCAAiC,EACjC,CACEnB,OAAO,CAACa,OAAO,CAAC,aAAa,CAAC,EAC9B;MACEiB,KAAK,EAAE;QACL,GAAG,EAAE,yBAAyB;QAC9B,MAAM,EAAE,2BAA2B;QACnC,WAAW,EAAE;MACf;IACF,CAAC,CACF;EAEL,CAAC,CAAC;EAEF,MAAMT,QAAQ,GAAG,MAAMC,eAAE,CAACC,QAAQ,CAACC,QAAQ,CACzCZ,iBAAI,CAACC,OAAO,CAACC,SAAS,EAAG,+CAA8C,CAAC,EACxE,MACF,CAAC;EAED,IAAAW,eAAM,EAACV,MAAM,EAAEW,IAAI,CAAC,CAACC,OAAO,CAACN,QAAQ,CAACO,IAAI,CAAC,CAAC,CAAC;AAC/C,CAAC,CAAC"}
package/lib/babel.js ADDED
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = _default;
7
+ var _fs = _interopRequireDefault(require("fs"));
8
+ var _path = _interopRequireDefault(require("path"));
9
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
+ const isFile = filename => {
11
+ const exists = _fs.default.lstatSync(filename, {
12
+ throwIfNoEntry: false
13
+ })?.isFile() ?? false;
14
+ return exists;
15
+ };
16
+ const isDirectory = filename => {
17
+ const exists = _fs.default.lstatSync(filename, {
18
+ throwIfNoEntry: false
19
+ })?.isDirectory() ?? false;
20
+ return exists;
21
+ };
22
+ const isTypeImport = node => 'importKind' in node && node.importKind === 'type' || 'exportKind' in node && node.exportKind === 'type';
23
+ const assertFilename = filename => {
24
+ if (filename == null) {
25
+ throw new Error("Couldn't find a filename for the current file.");
26
+ }
27
+ };
28
+ function _default(api, {
29
+ alias,
30
+ extension
31
+ }) {
32
+ api.assertVersion(7);
33
+ function aliasImports({
34
+ node
35
+ }, state) {
36
+ if (alias == null ||
37
+ // Skip type imports as they'll be removed
38
+ isTypeImport(node) ||
39
+ // Skip imports without a source
40
+ !node.source?.value) {
41
+ return;
42
+ }
43
+ assertFilename(state.filename);
44
+ const root = state.cwd;
45
+ const source = node.source.value;
46
+ for (const [key, value] of Object.entries(alias)) {
47
+ if (source === key || source.startsWith(`${key}/`)) {
48
+ const resolved = value.startsWith('.') ? _path.default.relative(_path.default.dirname(state.filename), _path.default.resolve(root, value)) : value;
49
+ node.source.value = source.replace(key, resolved);
50
+ return;
51
+ }
52
+ }
53
+ }
54
+ function addExtension({
55
+ node
56
+ }, state) {
57
+ if (extension == null ||
58
+ // Skip type imports as they'll be removed
59
+ isTypeImport(node) ||
60
+ // Skip non-relative imports
61
+ !node.source?.value.startsWith('.')) {
62
+ return;
63
+ }
64
+ assertFilename(state.filename);
65
+
66
+ // Skip folder imports
67
+ const filename = _path.default.resolve(_path.default.dirname(state.filename), node.source.value);
68
+
69
+ // Add extension if .ts file or file with extension exists
70
+ if (isFile(`${filename}.ts`) || isFile(`${filename}.tsx`) || isFile(`${filename}.${extension}`)) {
71
+ node.source.value += `.${extension}`;
72
+ return;
73
+ }
74
+
75
+ // Replace .ts extension with .js if .ts file exists
76
+ if (isFile(filename)) {
77
+ node.source.value = node.source.value.replace(/\.tsx?$/, `.${extension}`);
78
+ return;
79
+ }
80
+ if (isDirectory(filename) && (isFile(_path.default.join(filename, 'index.ts')) || isFile(_path.default.join(filename, 'index.tsx')) || isFile(_path.default.join(filename, `index.${extension}`)))) {
81
+ node.source.value = node.source.value.replace(/\/?$/, `/index.${extension}`);
82
+ return;
83
+ }
84
+ }
85
+ return {
86
+ name: '@builder-bob/babel-plugin',
87
+ visitor: {
88
+ ImportDeclaration(path, state) {
89
+ aliasImports(path, state);
90
+ addExtension(path, state);
91
+ },
92
+ ExportNamedDeclaration(path, state) {
93
+ aliasImports(path, state);
94
+ addExtension(path, state);
95
+ },
96
+ ExportAllDeclaration(path, state) {
97
+ aliasImports(path, state);
98
+ addExtension(path, state);
99
+ }
100
+ }
101
+ };
102
+ }
103
+ //# sourceMappingURL=babel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"babel.js","names":["_fs","_interopRequireDefault","require","_path","obj","__esModule","default","isFile","filename","exists","fs","lstatSync","throwIfNoEntry","isDirectory","isTypeImport","node","importKind","exportKind","assertFilename","Error","_default","api","alias","extension","assertVersion","aliasImports","state","source","value","root","cwd","key","Object","entries","startsWith","resolved","path","relative","dirname","resolve","replace","addExtension","join","name","visitor","ImportDeclaration","ExportNamedDeclaration","ExportAllDeclaration"],"sources":["../src/babel.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport type { ConfigAPI, NodePath, PluginObj, PluginPass } from '@babel/core';\nimport type {\n ImportDeclaration,\n ExportAllDeclaration,\n ExportNamedDeclaration,\n} from '@babel/types';\n\ntype Options = {\n alias?: Record<string, string>;\n extension?: 'cjs' | 'mjs';\n};\n\nconst isFile = (filename: string): boolean => {\n const exists =\n fs.lstatSync(filename, { throwIfNoEntry: false })?.isFile() ?? false;\n\n return exists;\n};\n\nconst isDirectory = (filename: string): boolean => {\n const exists =\n fs.lstatSync(filename, { throwIfNoEntry: false })?.isDirectory() ?? false;\n\n return exists;\n};\n\nconst isTypeImport = (\n node: ImportDeclaration | ExportNamedDeclaration | ExportAllDeclaration\n) =>\n ('importKind' in node && node.importKind === 'type') ||\n ('exportKind' in node && node.exportKind === 'type');\n\nconst assertFilename: (\n filename: string | null | undefined\n) => asserts filename is string = (filename) => {\n if (filename == null) {\n throw new Error(\"Couldn't find a filename for the current file.\");\n }\n};\n\nexport default function (\n api: ConfigAPI,\n { alias, extension }: Options\n): PluginObj {\n api.assertVersion(7);\n\n function aliasImports(\n {\n node,\n }: NodePath<\n ImportDeclaration | ExportNamedDeclaration | ExportAllDeclaration\n >,\n state: PluginPass\n ) {\n if (\n alias == null ||\n // Skip type imports as they'll be removed\n isTypeImport(node) ||\n // Skip imports without a source\n !node.source?.value\n ) {\n return;\n }\n\n assertFilename(state.filename);\n\n const root = state.cwd;\n const source = node.source.value;\n\n for (const [key, value] of Object.entries(alias)) {\n if (source === key || source.startsWith(`${key}/`)) {\n const resolved = value.startsWith('.')\n ? path.relative(\n path.dirname(state.filename),\n path.resolve(root, value)\n )\n : value;\n\n node.source.value = source.replace(key, resolved);\n return;\n }\n }\n }\n\n function addExtension(\n {\n node,\n }: NodePath<\n ImportDeclaration | ExportNamedDeclaration | ExportAllDeclaration\n >,\n state: PluginPass\n ) {\n if (\n extension == null ||\n // Skip type imports as they'll be removed\n isTypeImport(node) ||\n // Skip non-relative imports\n !node.source?.value.startsWith('.')\n ) {\n return;\n }\n\n assertFilename(state.filename);\n\n // Skip folder imports\n const filename = path.resolve(\n path.dirname(state.filename),\n node.source.value\n );\n\n // Add extension if .ts file or file with extension exists\n if (\n isFile(`${filename}.ts`) ||\n isFile(`${filename}.tsx`) ||\n isFile(`${filename}.${extension}`)\n ) {\n node.source.value += `.${extension}`;\n return;\n }\n\n // Replace .ts extension with .js if .ts file exists\n if (isFile(filename)) {\n node.source.value = node.source.value.replace(/\\.tsx?$/, `.${extension}`);\n return;\n }\n\n if (\n isDirectory(filename) &&\n (isFile(path.join(filename, 'index.ts')) ||\n isFile(path.join(filename, 'index.tsx')) ||\n isFile(path.join(filename, `index.${extension}`)))\n ) {\n node.source.value = node.source.value.replace(\n /\\/?$/,\n `/index.${extension}`\n );\n return;\n }\n }\n\n return {\n name: '@builder-bob/babel-plugin',\n visitor: {\n ImportDeclaration(path, state) {\n aliasImports(path, state);\n addExtension(path, state);\n },\n ExportNamedDeclaration(path, state) {\n aliasImports(path, state);\n addExtension(path, state);\n },\n ExportAllDeclaration(path, state) {\n aliasImports(path, state);\n addExtension(path, state);\n },\n },\n };\n}\n"],"mappings":";;;;;;AAAA,IAAAA,GAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,KAAA,GAAAF,sBAAA,CAAAC,OAAA;AAAwB,SAAAD,uBAAAG,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAaxB,MAAMG,MAAM,GAAIC,QAAgB,IAAc;EAC5C,MAAMC,MAAM,GACVC,WAAE,CAACC,SAAS,CAACH,QAAQ,EAAE;IAAEI,cAAc,EAAE;EAAM,CAAC,CAAC,EAAEL,MAAM,CAAC,CAAC,IAAI,KAAK;EAEtE,OAAOE,MAAM;AACf,CAAC;AAED,MAAMI,WAAW,GAAIL,QAAgB,IAAc;EACjD,MAAMC,MAAM,GACVC,WAAE,CAACC,SAAS,CAACH,QAAQ,EAAE;IAAEI,cAAc,EAAE;EAAM,CAAC,CAAC,EAAEC,WAAW,CAAC,CAAC,IAAI,KAAK;EAE3E,OAAOJ,MAAM;AACf,CAAC;AAED,MAAMK,YAAY,GAChBC,IAAuE,IAEtE,YAAY,IAAIA,IAAI,IAAIA,IAAI,CAACC,UAAU,KAAK,MAAM,IAClD,YAAY,IAAID,IAAI,IAAIA,IAAI,CAACE,UAAU,KAAK,MAAO;AAEtD,MAAMC,cAEyB,GAAIV,QAAQ,IAAK;EAC9C,IAAIA,QAAQ,IAAI,IAAI,EAAE;IACpB,MAAM,IAA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I,EAAEV,KAAK,CAAC;QACzBe,YAAY,CAACL,IAAI,EAAEV,KAAK,CAAC;MAC3B,CAAC;MACDoB,sBAAsBA,CAACV,IAAI,EAAEV,KAAK,EAAE;QAClCD,YAAY,CAACW,IAAI,EAAEV,KAAK,CAAC;QACzBe,YAAY,CAACL,IAAI,EAAEV,KAAK,CAAC;MAC3B,CAAC;MACDqB,oBAAoBA,CAACX,IAAI,EAAEV,KAAK,EAAE;QAChCD,YAAY,CAACW,IAAI,EAAEV,KAAK,CAAC;QACzBe,YAAY,CAACL,IAAI,EAAEV,KAAK,CAAC;MAC3B;IACF;EACF,CAAC;AACH"}
package/lib/index.js CHANGED
@@ -32,7 +32,7 @@ _yargs.default.command('init', 'configure the package to use bob', {}, async ()
32
32
  } = await (0, _prompts.default)({
33
33
  type: 'confirm',
34
34
  name: 'shouldContinue',
35
- message: `The working directory is not clean. You should commit or stash your changes before configuring bob. Continue anyway?`,
35
+ message: `The working directory is not clean.\n You should commit or stash your changes before configuring bob.\n Continue anyway?`,
36
36
  initial: false
37
37
  });
38
38
  if (!shouldContinue) {
@@ -41,7 +41,7 @@ _yargs.default.command('init', 'configure the package to use bob', {}, async ()
41
41
  }
42
42
  const pak = _path.default.join(root, 'package.json');
43
43
  if (!(await _fsExtra.default.pathExists(pak))) {
44
- logger.exit(`Couldn't find a 'package.json' file in '${root}'. Are you in a project folder?`);
44
+ logger.exit(`Couldn't find a 'package.json' file in '${root}'.\n Are you in a project folder?`);
45
45
  }
46
46
  const pkg = JSON.parse(await _fsExtra.default.readFile(pak, 'utf-8'));
47
47
  const result = explorer.search();
@@ -51,7 +51,7 @@ _yargs.default.command('init', 'configure the package to use bob', {}, async ()
51
51
  } = await (0, _prompts.default)({
52
52
  type: 'confirm',
53
53
  name: 'shouldContinue',
54
- message: `The project seems to be already configured with bob. Do you want to overwrite the existing configuration?`,
54
+ message: `The project seems to be already configured with bob.\n Do you want to overwrite the existing configuration?`,
55
55
  initial: false
56
56
  });
57
57
  if (!shouldContinue) {
@@ -76,7 +76,7 @@ _yargs.default.command('init', 'configure the package to use bob', {}, async ()
76
76
  entryFile = 'index.tsx';
77
77
  }
78
78
  if (!entryFile) {
79
- logger.exit(`Couldn't find a 'index.js'. 'index.ts' or 'index.tsx' file under '${source}'. Please re-run the CLI after creating it.`);
79
+ logger.exit(`Couldn't find a 'index.js'. 'index.ts' or 'index.tsx' file under '${source}'.\n Please re-run the CLI after creating it.`);
80
80
  return;
81
81
  }
82
82
  pkg.devDependencies = Object.fromEntries([...Object.entries(pkg.devDependencies || {}), [name, `^${version}`]].sort(([a], [b]) => a.localeCompare(b)));
@@ -120,22 +120,21 @@ _yargs.default.command('init', 'configure the package to use bob', {}, async ()
120
120
  } = await (0, _prompts.default)(questions);
121
121
  const target = targets[0] === 'commonjs' || targets[0] === 'module' ? targets[0] : undefined;
122
122
  const entries = {
123
- 'main': target ? _path.default.join(output, target, 'index.js') : _path.default.join(source, entryFile),
124
- 'react-native': _path.default.join(source, entryFile),
125
- 'source': _path.default.join(source, entryFile)
123
+ source: `./${_path.default.join(source, entryFile)}`,
124
+ main: `./${target ? _path.default.join(output, target, 'index.cjs') : _path.default.join(source, entryFile)}`
126
125
  };
127
126
  if (targets.includes('module')) {
128
- entries.module = _path.default.join(output, 'module', 'index.js');
127
+ entries.module = `./${_path.default.join(output, 'module', 'index.mjs')}`;
129
128
  }
130
129
  if (targets.includes('typescript')) {
131
- entries.types = _path.default.join(output, 'typescript', source, 'index.d.ts');
130
+ entries.types = `./${_path.default.join(output, 'typescript', source, 'index.d.ts')}`;
132
131
  if (!(await _fsExtra.default.pathExists(_path.default.join(root, 'tsconfig.json')))) {
133
132
  const {
134
133
  tsconfig
135
134
  } = await (0, _prompts.default)({
136
135
  type: 'confirm',
137
136
  name: 'tsconfig',
138
- message: `You have enabled 'typescript' compilation, but we couldn't find a 'tsconfig.json' in project root. Generate one?`,
137
+ message: `You have enabled 'typescript' compilation, but we couldn't find a 'tsconfig.json' in project root.\n Generate one?`,
139
138
  initial: true
140
139
  });
141
140
  if (tsconfig) {
@@ -146,10 +145,10 @@ _yargs.default.command('init', 'configure the package to use bob', {}, async ()
146
145
  allowUnusedLabels: false,
147
146
  esModuleInterop: true,
148
147
  forceConsistentCasingInFileNames: true,
149
- jsx: 'react',
150
- lib: ['esnext'],
151
- module: 'esnext',
152
- moduleResolution: 'node',
148
+ jsx: 'react-jsx',
149
+ lib: ['ESNext'],
150
+ module: 'ESNext',
151
+ moduleResolution: 'Bundler',
153
152
  noFallthroughCasesInSwitch: true,
154
153
  noImplicitReturns: true,
155
154
  noImplicitUseStrict: false,
@@ -160,7 +159,7 @@ _yargs.default.command('init', 'configure the package to use bob', {}, async ()
160
159
  resolveJsonModule: true,
161
160
  skipLibCheck: true,
162
161
  strict: true,
163
- target: 'esnext',
162
+ target: 'ESNext',
164
163
  verbatimModuleSyntax: true
165
164
  }
166
165
  }, {
@@ -179,7 +178,7 @@ _yargs.default.command('init', 'configure the package to use bob', {}, async ()
179
178
  } = await (0, _prompts.default)({
180
179
  type: 'confirm',
181
180
  name: 'replace',
182
- message: `Your package.json has the '${key}' field set to '${pkg[key]}'. Do you want to replace it with '${entry}'?`,
181
+ message: `Your package.json has the '${key}' field set to '${pkg[key]}'.\n Do you want to replace it with '${entry}'?`,
183
182
  initial: true
184
183
  });
185
184
  if (replace) {
@@ -189,13 +188,55 @@ _yargs.default.command('init', 'configure the package to use bob', {}, async ()
189
188
  pkg[key] = entry;
190
189
  }
191
190
  }
191
+ if (Object.values(entries).some(entry => entry.endsWith('.mjs'))) {
192
+ let replace = false;
193
+ const exports = {
194
+ '.': {
195
+ ...(entries.types ? {
196
+ types: entries.types
197
+ } : null),
198
+ ...(entries.module ? {
199
+ import: entries.module
200
+ } : null),
201
+ ...(entries.main ? {
202
+ require: entries.main
203
+ } : null)
204
+ }
205
+ };
206
+ if (pkg.exports && JSON.stringify(pkg.exports) !== JSON.stringify(exports)) {
207
+ replace = (await (0, _prompts.default)({
208
+ type: 'confirm',
209
+ name: 'replace',
210
+ message: `Your package.json has 'exports' field set.\n Do you want to replace it?`,
211
+ initial: true
212
+ })).replace;
213
+ } else {
214
+ replace = true;
215
+ }
216
+ if (replace) {
217
+ pkg.exports = exports;
218
+ }
219
+ }
220
+ if (pkg['react-native'] && (pkg['react-native'].startsWith(source) || pkg['react-native'].startsWith(`./${source}`))) {
221
+ const {
222
+ remove
223
+ } = await (0, _prompts.default)({
224
+ type: 'confirm',
225
+ name: 'remove',
226
+ 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?`,
227
+ initial: true
228
+ });
229
+ if (remove) {
230
+ delete pkg['react-native'];
231
+ }
232
+ }
192
233
  if (pkg.scripts?.prepare && pkg.scripts.prepare !== prepare) {
193
234
  const {
194
235
  replace
195
236
  } = await (0, _prompts.default)({
196
237
  type: 'confirm',
197
238
  name: 'replace',
198
- message: `Your package.json has the 'scripts.prepare' field set to '${pkg.scripts.prepare}'. Do you want to replace it with '${prepare}'?`,
239
+ message: `Your package.json has the 'scripts.prepare' field set to '${pkg.scripts.prepare}'.\n Do you want to replace it with '${prepare}'?`,
199
240
  initial: true
200
241
  });
201
242
  if (replace) {
@@ -211,7 +252,7 @@ _yargs.default.command('init', 'configure the package to use bob', {}, async ()
211
252
  } = await (0, _prompts.default)({
212
253
  type: 'confirm',
213
254
  name: 'update',
214
- message: `Your package.json already has a 'files' field. Do you want to update it?`,
255
+ message: `Your package.json already has a 'files' field.\n Do you want to update it?`,
215
256
  initial: true
216
257
  });
217
258
  if (update) {