@teambit/react 0.0.732 → 0.0.735
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/apps/web/plugins/index.ts +1 -1
- package/apps/web/plugins/prerender.ts +5 -13
- package/apps/web/react-app-options.ts +44 -3
- package/apps/web/react.application.ts +2 -2
- package/artifacts/env-template/public/117.js +34 -0
- package/artifacts/env-template/public/{283.js → 149.js} +2 -2
- package/artifacts/env-template/public/{793.js → 295.js} +63 -67
- package/artifacts/env-template/public/677.js +5 -5
- package/artifacts/env-template/public/750.js +6 -6
- package/artifacts/env-template/public/{764.js → 994.js} +6 -6
- package/artifacts/env-template/public/assets-manifest.json +21 -21
- package/artifacts/env-template/public/{compositions.3604561f89c7643dae7b.js → compositions.ff40db501672bede5e3f.js} +1 -1
- package/artifacts/env-template/public/compositions.html +1 -1
- package/artifacts/env-template/public/{overview.87ea5e32ca6eab940eb6.js → overview.9ee03c1e295a357f7aa0.js} +1 -1
- package/artifacts/env-template/public/overview.html +1 -1
- package/artifacts/env-template/public/peers.edfbd1f8ec8a3331b9ac.js +1 -0
- package/artifacts/env-template/public/{preview-root.7e877ecceb7548ad9faa.js → preview-root.7a24e602c0fa0ba9f5f1.js} +1 -1
- package/artifacts/env-template/public/service-worker.js +1 -1
- package/artifacts/env-template/public/static/css/295.e370e333.css +1 -0
- package/artifacts/preview/teambit_react_react-preview.js +2 -2
- package/{compositions-1652671504464.js → compositions-1652808661748.js} +0 -0
- package/dist/apps/web/plugins/index.d.ts +1 -1
- package/dist/apps/web/plugins/index.js +2 -2
- package/dist/apps/web/plugins/index.js.map +1 -1
- package/dist/apps/web/plugins/prerender.d.ts +1 -1
- package/dist/apps/web/plugins/prerender.js +12 -21
- package/dist/apps/web/plugins/prerender.js.map +1 -1
- package/dist/apps/web/react-app-options.d.ts +32 -2
- package/dist/apps/web/react.application.js +1 -1
- package/dist/apps/web/react.application.js.map +1 -1
- package/dist/react.env.js +2 -1
- package/dist/react.env.js.map +1 -1
- package/dist/webpack/get-exposed-rules.d.ts +2 -1
- package/dist/webpack/get-exposed-rules.js +12 -2
- package/dist/webpack/get-exposed-rules.js.map +1 -1
- package/dist/webpack/resolve-peer.d.ts +14 -0
- package/dist/webpack/resolve-peer.js +108 -0
- package/dist/webpack/resolve-peer.js.map +1 -0
- package/dist/webpack/transformers.d.ts +8 -1
- package/dist/webpack/transformers.js +37 -39
- package/dist/webpack/transformers.js.map +1 -1
- package/dist/webpack/webpack.config.base.prod.js +0 -15
- package/dist/webpack/webpack.config.base.prod.js.map +1 -1
- package/{overview-1652671504464.js → overview-1652808661748.js} +0 -0
- package/package-tar/teambit-react-0.0.735.tgz +0 -0
- package/package.json +35 -33
- package/{preview-1652671504464.js → preview-1652808661748.js} +2 -2
- package/webpack/get-exposed-rules.ts +4 -2
- package/webpack/resolve-peer.ts +60 -0
- package/webpack/transformers.ts +24 -33
- package/webpack/webpack.config.base.prod.ts +0 -9
- package/artifacts/env-template/public/15.js +0 -34
- package/artifacts/env-template/public/peers.dbfbae2daf17fd0c329d.js +0 -1
- package/artifacts/env-template/public/static/css/793.52d87d5e.css +0 -1
- package/package-tar/teambit-react-0.0.732.tgz +0 -0
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.resolvePeerToDirOrFile = resolvePeerToDirOrFile;
|
|
9
|
+
exports.resolvePeerToFile = resolvePeerToFile;
|
|
10
|
+
|
|
11
|
+
function _fs() {
|
|
12
|
+
const data = _interopRequireWildcard(require("fs"));
|
|
13
|
+
|
|
14
|
+
_fs = function () {
|
|
15
|
+
return data;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
return data;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function _enhancedResolve() {
|
|
22
|
+
const data = require("enhanced-resolve");
|
|
23
|
+
|
|
24
|
+
_enhancedResolve = function () {
|
|
25
|
+
return data;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
return data;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function _findRoot() {
|
|
32
|
+
const data = _interopRequireDefault(require("find-root"));
|
|
33
|
+
|
|
34
|
+
_findRoot = function () {
|
|
35
|
+
return data;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
return data;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
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); }
|
|
42
|
+
|
|
43
|
+
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; }
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Get the package folder, and in case it's not found get the resolved file path
|
|
47
|
+
* @param peerName
|
|
48
|
+
* @returns
|
|
49
|
+
*/
|
|
50
|
+
function resolvePeerToDirOrFile(peerName, logger, hostRootDir) {
|
|
51
|
+
let resolved;
|
|
52
|
+
|
|
53
|
+
try {
|
|
54
|
+
let options;
|
|
55
|
+
|
|
56
|
+
if (hostRootDir) {
|
|
57
|
+
options = {
|
|
58
|
+
// resolve the host root dir to its real location, as require.resolve is preserve symlink, so we get wrong result otherwise
|
|
59
|
+
paths: [(0, _fs().realpathSync)(hostRootDir), __dirname]
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
resolved = require.resolve(peerName, options);
|
|
64
|
+
const folder = (0, _findRoot().default)(resolved);
|
|
65
|
+
return folder;
|
|
66
|
+
} catch (e) {
|
|
67
|
+
if (resolved) {
|
|
68
|
+
logger.warn(`Couldn't find root dir for "${peerName}" from path "${resolved}" to add it as webpack alias`);
|
|
69
|
+
} else {
|
|
70
|
+
logger.warn(`Couldn't resolve "${peerName}" to add it as webpack alias`);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return resolved;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Make sure to resolve the peer path correctly
|
|
78
|
+
* we first resolve it to its dir (to be aligned with the aliases transformer)
|
|
79
|
+
* Then we resolve it to specific file, using enhanced resolve to make sure we resolve it using the correct main fields order
|
|
80
|
+
* @param peer
|
|
81
|
+
*/
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
function resolvePeerToFile(peer, logger, hostRootDir) {
|
|
85
|
+
const dirOrFile = resolvePeerToDirOrFile(peer, logger, hostRootDir);
|
|
86
|
+
const resolver = createResolver();
|
|
87
|
+
const resolvedFile = resolver.resolveSync({}, '', dirOrFile);
|
|
88
|
+
return resolvedFile;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Generate a resolver that will read first the module field then the main field
|
|
92
|
+
* to make it compatible with webpack behavior
|
|
93
|
+
* @returns
|
|
94
|
+
*/
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
function createResolver() {
|
|
98
|
+
// create a resolver
|
|
99
|
+
const myResolver = _enhancedResolve().ResolverFactory.createResolver({
|
|
100
|
+
fileSystem: new (_enhancedResolve().CachedInputFileSystem)(_fs().default, 4000),
|
|
101
|
+
useSyncFileSystemCalls: true,
|
|
102
|
+
mainFields: ['module', 'main']
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
return myResolver;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
//# sourceMappingURL=resolve-peer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["resolve-peer.ts"],"names":["resolvePeerToDirOrFile","peerName","logger","hostRootDir","resolved","options","paths","__dirname","require","resolve","folder","e","warn","resolvePeerToFile","peer","dirOrFile","resolver","createResolver","resolvedFile","resolveSync","myResolver","ResolverFactory","fileSystem","CachedInputFileSystem","fs","useSyncFileSystemCalls","mainFields"],"mappings":";;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;;;;;AAGA;AACA;AACA;AACA;AACA;AACO,SAASA,sBAAT,CAAgCC,QAAhC,EAAkDC,MAAlD,EAAkEC,WAAlE,EAA4G;AACjH,MAAIC,QAAJ;;AACA,MAAI;AACF,QAAIC,OAAJ;;AACA,QAAIF,WAAJ,EAAiB;AACfE,MAAAA,OAAO,GAAG;AACR;AACAC,QAAAA,KAAK,EAAE,CAAC,wBAAaH,WAAb,CAAD,EAA4BI,SAA5B;AAFC,OAAV;AAID;;AACDH,IAAAA,QAAQ,GAAGI,OAAO,CAACC,OAAR,CAAgBR,QAAhB,EAA0BI,OAA1B,CAAX;AACA,UAAMK,MAAM,GAAG,yBAASN,QAAT,CAAf;AACA,WAAOM,MAAP;AACD,GAXD,CAWE,OAAOC,CAAP,EAAU;AACV,QAAIP,QAAJ,EAAc;AACZF,MAAAA,MAAM,CAACU,IAAP,CAAa,+BAA8BX,QAAS,gBAAeG,QAAS,8BAA5E;AACD,KAFD,MAEO;AACLF,MAAAA,MAAM,CAACU,IAAP,CAAa,qBAAoBX,QAAS,8BAA1C;AACD;;AACD,WAAOG,QAAP;AACD;AACF;AAED;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASS,iBAAT,CAA2BC,IAA3B,EAAyCZ,MAAzC,EAAyDC,WAAzD,EAA+E;AACpF,QAAMY,SAAS,GAAGf,sBAAsB,CAACc,IAAD,EAAOZ,MAAP,EAAeC,WAAf,CAAxC;AACA,QAAMa,QAAQ,GAAGC,cAAc,EAA/B;AACA,QAAMC,YAAY,GAAGF,QAAQ,CAACG,WAAT,CAAqB,EAArB,EAAyB,EAAzB,EAA6BJ,SAA7B,CAArB;AACA,SAAOG,YAAP;AACD;AAED;AACA;AACA;AACA;AACA;;;AACA,SAASD,cAAT,GAA0B;AACxB;AACA,QAAMG,UAAU,GAAGC,mCAAgBJ,cAAhB,CAA+B;AAChDK,IAAAA,UAAU,EAAE,KAAIC,wCAAJ,EAA0BC,aAA1B,EAA8B,IAA9B,CADoC;AAEhDC,IAAAA,sBAAsB,EAAE,IAFwB;AAGhDC,IAAAA,UAAU,EAAE,CAAC,QAAD,EAAW,MAAX;AAHoC,GAA/B,CAAnB;;AAKA,SAAON,UAAP;AACD","sourcesContent":["import fs, { realpathSync } from 'fs';\nimport { ResolverFactory, CachedInputFileSystem } from 'enhanced-resolve';\nimport findRoot from 'find-root';\nimport { Logger } from '@teambit/logger';\n\n/**\n * Get the package folder, and in case it's not found get the resolved file path\n * @param peerName\n * @returns\n */\nexport function resolvePeerToDirOrFile(peerName: string, logger: Logger, hostRootDir?: string): string | undefined {\n let resolved;\n try {\n let options;\n if (hostRootDir) {\n options = {\n // resolve the host root dir to its real location, as require.resolve is preserve symlink, so we get wrong result otherwise\n paths: [realpathSync(hostRootDir), __dirname],\n };\n }\n resolved = require.resolve(peerName, options);\n const folder = findRoot(resolved);\n return folder;\n } catch (e) {\n if (resolved) {\n logger.warn(`Couldn't find root dir for \"${peerName}\" from path \"${resolved}\" to add it as webpack alias`);\n } else {\n logger.warn(`Couldn't resolve \"${peerName}\" to add it as webpack alias`);\n }\n return resolved;\n }\n}\n\n/**\n * Make sure to resolve the peer path correctly\n * we first resolve it to its dir (to be aligned with the aliases transformer)\n * Then we resolve it to specific file, using enhanced resolve to make sure we resolve it using the correct main fields order\n * @param peer\n */\nexport function resolvePeerToFile(peer: string, logger: Logger, hostRootDir?: string) {\n const dirOrFile = resolvePeerToDirOrFile(peer, logger, hostRootDir);\n const resolver = createResolver();\n const resolvedFile = resolver.resolveSync({}, '', dirOrFile);\n return resolvedFile;\n}\n\n/**\n * Generate a resolver that will read first the module field then the main field\n * to make it compatible with webpack behavior\n * @returns\n */\nfunction createResolver() {\n // create a resolver\n const myResolver = ResolverFactory.createResolver({\n fileSystem: new CachedInputFileSystem(fs, 4000),\n useSyncFileSystemCalls: true,\n mainFields: ['module', 'main'],\n });\n return myResolver;\n}\n"]}
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
import { WebpackConfigTransformContext } from '@teambit/webpack';
|
|
1
2
|
import { WebpackConfigMutator } from '@teambit/webpack.modules.config-mutator';
|
|
2
3
|
import { Logger } from '@teambit/logger';
|
|
3
|
-
export declare function generateAddAliasesFromPeersTransformer(peers: string[], logger: Logger): (config: WebpackConfigMutator) => WebpackConfigMutator;
|
|
4
|
+
export declare function generateAddAliasesFromPeersTransformer(peers: string[], logger: Logger): (config: WebpackConfigMutator, context: WebpackConfigTransformContext) => WebpackConfigMutator;
|
|
5
|
+
/**
|
|
6
|
+
* Generate a transformer that expose all the peers as global via the expose loader
|
|
7
|
+
* @param peers
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
10
|
+
export declare function generateExposePeersTransformer(peers: string[], logger: Logger): (config: WebpackConfigMutator, context: WebpackConfigTransformContext) => WebpackConfigMutator;
|
|
@@ -1,68 +1,66 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
3
|
Object.defineProperty(exports, "__esModule", {
|
|
6
4
|
value: true
|
|
7
5
|
});
|
|
8
6
|
exports.generateAddAliasesFromPeersTransformer = generateAddAliasesFromPeersTransformer;
|
|
7
|
+
exports.generateExposePeersTransformer = generateExposePeersTransformer;
|
|
9
8
|
|
|
10
|
-
function
|
|
11
|
-
const data =
|
|
9
|
+
function _getExposedRules() {
|
|
10
|
+
const data = require("./get-exposed-rules");
|
|
12
11
|
|
|
13
|
-
|
|
12
|
+
_getExposedRules = function () {
|
|
14
13
|
return data;
|
|
15
14
|
};
|
|
16
15
|
|
|
17
16
|
return data;
|
|
18
17
|
}
|
|
19
18
|
|
|
20
|
-
function
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
// node_modules/react-dom/index.js/test-utils
|
|
30
|
-
const resolved = getResolvedDirOrFile(peerName, logger);
|
|
19
|
+
function _resolvePeer() {
|
|
20
|
+
const data = require("./resolve-peer");
|
|
21
|
+
|
|
22
|
+
_resolvePeer = function () {
|
|
23
|
+
return data;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
return data;
|
|
27
|
+
}
|
|
31
28
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
29
|
+
function generateAddAliasesFromPeersTransformer(peers, logger) {
|
|
30
|
+
return (config, context) => {
|
|
31
|
+
const peerAliases = peers.reduce((acc, peerName) => {
|
|
32
|
+
var _context$target;
|
|
35
33
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
34
|
+
// gets the correct module folder of the package.
|
|
35
|
+
// this allows us to resolve internal files, for example:
|
|
36
|
+
// node_modules/react-dom/test-utils
|
|
37
|
+
//
|
|
38
|
+
// we can't use require.resolve() because it resolves to a specific file.
|
|
39
|
+
// for example, if we used "react-dom": require.resolve("react-dom"),
|
|
40
|
+
// it would try to resolve "react-dom/test-utils" as:
|
|
41
|
+
// node_modules/react-dom/index.js/test-utils
|
|
42
|
+
acc[peerName] = (0, _resolvePeer().resolvePeerToDirOrFile)(peerName, logger, (_context$target = context.target) === null || _context$target === void 0 ? void 0 : _context$target.hostRootDir);
|
|
43
|
+
return acc;
|
|
44
|
+
}, {});
|
|
39
45
|
config.addAliases(peerAliases);
|
|
40
46
|
return config;
|
|
41
47
|
};
|
|
42
48
|
}
|
|
43
49
|
/**
|
|
44
|
-
*
|
|
45
|
-
* @param
|
|
50
|
+
* Generate a transformer that expose all the peers as global via the expose loader
|
|
51
|
+
* @param peers
|
|
46
52
|
* @returns
|
|
47
53
|
*/
|
|
48
54
|
|
|
49
55
|
|
|
50
|
-
function
|
|
51
|
-
|
|
56
|
+
function generateExposePeersTransformer(peers, logger) {
|
|
57
|
+
return (config, context) => {
|
|
58
|
+
var _context$target2;
|
|
52
59
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
} catch (e) {
|
|
58
|
-
if (resolved) {
|
|
59
|
-
logger.warn(`Couldn't find root dir for "${peerName}" from path "${resolved}" to add it as webpack alias`);
|
|
60
|
-
} else {
|
|
61
|
-
logger.warn(`Couldn't resolve "${peerName}" to add it as webpack alias`);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
return resolved;
|
|
65
|
-
}
|
|
60
|
+
const exposedRules = (0, _getExposedRules().getExposedRules)(peers, logger, (_context$target2 = context.target) === null || _context$target2 === void 0 ? void 0 : _context$target2.hostRootDir);
|
|
61
|
+
config.addModuleRules(exposedRules);
|
|
62
|
+
return config;
|
|
63
|
+
};
|
|
66
64
|
}
|
|
67
65
|
|
|
68
66
|
//# sourceMappingURL=transformers.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["transformers.ts"],"names":["generateAddAliasesFromPeersTransformer","peers","logger","
|
|
1
|
+
{"version":3,"sources":["transformers.ts"],"names":["generateAddAliasesFromPeersTransformer","peers","logger","config","context","peerAliases","reduce","acc","peerName","target","hostRootDir","addAliases","generateExposePeersTransformer","exposedRules","addModuleRules"],"mappings":";;;;;;;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEO,SAASA,sCAAT,CAAgDC,KAAhD,EAAiEC,MAAjE,EAAiF;AACtF,SAAO,CAACC,MAAD,EAA+BC,OAA/B,KAAgG;AACrG,UAAMC,WAAW,GAAGJ,KAAK,CAACK,MAAN,CAAa,CAACC,GAAD,EAAMC,QAAN,KAAmB;AAAA;;AAClD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACAD,MAAAA,GAAG,CAACC,QAAD,CAAH,GAAgB,2CAAuBA,QAAvB,EAAiCN,MAAjC,qBAAyCE,OAAO,CAACK,MAAjD,oDAAyC,gBAAgBC,WAAzD,CAAhB;AACA,aAAOH,GAAP;AACD,KAXmB,EAWjB,EAXiB,CAApB;AAYAJ,IAAAA,MAAM,CAACQ,UAAP,CAAkBN,WAAlB;AACA,WAAOF,MAAP;AACD,GAfD;AAgBD;AAED;AACA;AACA;AACA;AACA;;;AACO,SAASS,8BAAT,CAAwCX,KAAxC,EAAyDC,MAAzD,EAAyE;AAC9E,SAAO,CAACC,MAAD,EAA+BC,OAA/B,KAAgG;AAAA;;AACrG,UAAMS,YAAY,GAAG,wCAAgBZ,KAAhB,EAAuBC,MAAvB,sBAA+BE,OAAO,CAACK,MAAvC,qDAA+B,iBAAgBC,WAA/C,CAArB;AACAP,IAAAA,MAAM,CAACW,cAAP,CAAsBD,YAAtB;AACA,WAAOV,MAAP;AACD,GAJD;AAKD","sourcesContent":["import { WebpackConfigTransformContext } from '@teambit/webpack';\nimport { WebpackConfigMutator } from '@teambit/webpack.modules.config-mutator';\nimport { Logger } from '@teambit/logger';\nimport { getExposedRules } from './get-exposed-rules';\nimport { resolvePeerToDirOrFile } from './resolve-peer';\n\nexport function generateAddAliasesFromPeersTransformer(peers: string[], logger: Logger) {\n return (config: WebpackConfigMutator, context: WebpackConfigTransformContext): WebpackConfigMutator => {\n const peerAliases = peers.reduce((acc, peerName) => {\n // gets the correct module folder of the package.\n // this allows us to resolve internal files, for example:\n // node_modules/react-dom/test-utils\n //\n // we can't use require.resolve() because it resolves to a specific file.\n // for example, if we used \"react-dom\": require.resolve(\"react-dom\"),\n // it would try to resolve \"react-dom/test-utils\" as:\n // node_modules/react-dom/index.js/test-utils\n acc[peerName] = resolvePeerToDirOrFile(peerName, logger, context.target?.hostRootDir);\n return acc;\n }, {});\n config.addAliases(peerAliases);\n return config;\n };\n}\n\n/**\n * Generate a transformer that expose all the peers as global via the expose loader\n * @param peers\n * @returns\n */\nexport function generateExposePeersTransformer(peers: string[], logger: Logger) {\n return (config: WebpackConfigMutator, context: WebpackConfigTransformContext): WebpackConfigMutator => {\n const exposedRules = getExposedRules(peers, logger, context.target?.hostRootDir);\n config.addModuleRules(exposedRules);\n return config;\n };\n}\n"]}
|
|
@@ -51,26 +51,12 @@ function _getExternals() {
|
|
|
51
51
|
return data;
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
function _getExposedRules() {
|
|
55
|
-
const data = require("./get-exposed-rules");
|
|
56
|
-
|
|
57
|
-
_getExposedRules = function () {
|
|
58
|
-
return data;
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
return data;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
54
|
// import { WebpackManifestPlugin } from 'webpack-manifest-plugin';
|
|
65
55
|
// This is the production and development configuration.
|
|
66
56
|
// It is focused on developer experience, fast rebuilds, and a minimal bundle.
|
|
67
57
|
// eslint-disable-next-line complexity
|
|
68
58
|
function _default(externalizePeer, peers, dev) {
|
|
69
59
|
const externals = externalizePeer ? (0, _getExternals().getExternals)(peers) : undefined;
|
|
70
|
-
const exposedRules = externalizePeer ? undefined : (0, _getExposedRules().getExposedRules)(peers);
|
|
71
|
-
const module = externalizePeer ? undefined : {
|
|
72
|
-
rules: exposedRules
|
|
73
|
-
};
|
|
74
60
|
const optimization = dev ? undefined : {
|
|
75
61
|
minimize: true,
|
|
76
62
|
minimizer: [new (_terserWebpackPlugin().default)({
|
|
@@ -149,7 +135,6 @@ function _default(externalizePeer, peers, dev) {
|
|
|
149
135
|
|
|
150
136
|
};
|
|
151
137
|
return {
|
|
152
|
-
module,
|
|
153
138
|
externals,
|
|
154
139
|
optimization,
|
|
155
140
|
plugins: [// Generate an asset manifest file with the following content:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["webpack.config.base.prod.ts"],"names":["externalizePeer","peers","dev","externals","undefined","
|
|
1
|
+
{"version":3,"sources":["webpack.config.base.prod.ts"],"names":["externalizePeer","peers","dev","externals","undefined","optimization","minimize","minimizer","TerserPlugin","minify","esbuildMinify","terserOptions","minifyWhitespace","minifyIdentifiers","minifySyntax","CssMinimizerPlugin","minimizerOptions","preset","minifyFontValues","removeQuotes","plugins","WorkboxWebpackPlugin","GenerateSW","clientsClaim","exclude","navigateFallback","navigateFallbackDenylist","RegExp","filter","Boolean","performance"],"mappings":";;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAEA;AACA;AACA;AACe,kBAAUA,eAAV,EAAoCC,KAApC,EAAqDC,GAArD,EAAmF;AAChG,QAAMC,SAAS,GAAGH,eAAe,GAAI,kCAAaC,KAAb,CAAJ,GAAkCG,SAAnE;AAEA,QAAMC,YAAY,GAAGH,GAAG,GACpBE,SADoB,GAEpB;AACEE,IAAAA,QAAQ,EAAE,IADZ;AAEEC,IAAAA,SAAS,EAAE,CACT,KAAIC,8BAAJ,EAAiB;AACfC,MAAAA,MAAM,EAAED,+BAAaE,aADN;AAEf;AACA;AACA;AACAC,MAAAA,aAAa,EAAE;AACbF,QAAAA,MAAM,EAAE,KADK;AAEbG,QAAAA,gBAAgB,EAAE,IAFL;AAGb;AACAC,QAAAA,iBAAiB,EAAE,KAJN;AAKb;AACAC,QAAAA,YAAY,EAAE;AAND,OALA,CAaf;;AAbe,KAAjB,CADS,EAiBT;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAIC,oCAAJ,EAAuB;AACrBC,MAAAA,gBAAgB,EAAE;AAChBC,QAAAA,MAAM,EAAE,CACN,SADM,EAEN;AACEC,UAAAA,gBAAgB,EAAE;AAAEC,YAAAA,YAAY,EAAE;AAAhB;AADpB,SAFM;AADQ;AADG,KAAvB,CAvDS,CAFb,CAoEE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAhFF,GAFJ;AAqFA,SAAO;AACLhB,IAAAA,SADK;AAELE,IAAAA,YAFK;AAILe,IAAAA,OAAO,EAAE,CACP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAIC,gCAAqBC,UAAzB,EAAoC;AAClCC,MAAAA,YAAY,EAAE,IADoB;AAElCC,MAAAA,OAAO,EAAE,CAAC,QAAD,EAAW,uBAAX,CAFyB;AAGlC;AACAC,MAAAA,gBAAgB,EAAE,mBAJgB;AAKlCC,MAAAA,wBAAwB,EAAE,CACxB;AACA,UAAIC,MAAJ,CAAW,KAAX,CAFwB,EAGxB;AACA;AACA;AACA;AACA,UAAIA,MAAJ,CAAW,kBAAX,CAPwB;AALQ,KAApC,CAzBO,EAwCPC,MAxCO,CAwCAC,OAxCA,CAJJ;AA6CL;AACA;AACAC,IAAAA,WAAW,EAAE;AA/CR,GAAP;AAiDD","sourcesContent":["import WorkboxWebpackPlugin from 'workbox-webpack-plugin';\nimport CssMinimizerPlugin from 'css-minimizer-webpack-plugin';\nimport TerserPlugin from 'terser-webpack-plugin';\nimport { Configuration } from 'webpack';\nimport { getExternals } from './get-externals';\n// import { WebpackManifestPlugin } from 'webpack-manifest-plugin';\n\n// This is the production and development configuration.\n// It is focused on developer experience, fast rebuilds, and a minimal bundle.\n// eslint-disable-next-line complexity\nexport default function (externalizePeer: boolean, peers: string[], dev?: boolean): Configuration {\n const externals = externalizePeer ? (getExternals(peers) as any) : undefined;\n\n const optimization = dev\n ? undefined\n : {\n minimize: true,\n minimizer: [\n new TerserPlugin({\n minify: TerserPlugin.esbuildMinify,\n // `terserOptions` options will be passed to `esbuild`\n // Link to options - https://esbuild.github.io/api/#minify\n // Note: the `minify` options is true by default (and override other `minify*` options), so if you want to disable the `minifyIdentifiers` option (or other `minify*` options) please use:\n terserOptions: {\n minify: false,\n minifyWhitespace: true,\n // We don't want to minify identifiers to enable easier debugging on remote scopes when there are preview issues\n minifyIdentifiers: false,\n // minifyIdentifiers: true,\n minifySyntax: true,\n },\n // terserOptions: {},\n }),\n\n // This is only used in production mode\n // new TerserPlugin({\n // extractComments: false,\n // terserOptions: {\n // parse: {\n // // We want terser to parse ecma 8 code. However, we don't want it\n // // to apply any minification steps that turns valid ecma 5 code\n // // into invalid ecma 5 code. This is why the 'compress' and 'output'\n // // sections only apply transformations that are ecma 5 safe\n // // https://github.com/facebook/create-react-app/pull/4234\n // ecma: 8,\n // },\n // compress: {\n // ecma: 5,\n // warnings: false,\n // // Disabled because of an issue with Uglify breaking seemingly valid code:\n // // https://github.com/facebook/create-react-app/issues/2376\n // // Pending further investigation:\n // // https://github.com/mishoo/UglifyJS2/issues/2011\n // comparisons: false,\n // // Disabled because of an issue with Terser breaking valid code:\n // // https://github.com/facebook/create-react-app/issues/5250\n // // Pending further investigation:\n // // https://github.com/terser-js/terser/issues/120\n // inline: 2,\n // },\n // mangle: {\n // safari10: true,\n // },\n // output: {\n // ecma: 5,\n // comments: false,\n // // Turned on because emoji and regex is not minified properly using default\n // // https://github.com/facebook/create-react-app/issues/2488\n // ascii_only: true,\n // },\n // },\n // }),\n new CssMinimizerPlugin({\n minimizerOptions: {\n preset: [\n 'default',\n {\n minifyFontValues: { removeQuotes: false },\n },\n ],\n },\n }),\n ],\n // Automatically split vendor and commons\n // https://twitter.com/wSokra/status/969633336732905474\n // https://medium.com/webpack/webpack-4-code-splitting-chunk-graph-and-the-splitchunks-optimization-be739a861366\n // splitChunks: {\n // chunks: 'all',\n // name: false,\n // },\n // Keep the runtime chunk separated to enable long term caching\n // https://twitter.com/wSokra/status/969679223278505985\n // https://github.com/facebook/create-react-app/issues/5358\n // runtimeChunk: {\n // name: (entrypoint) => `runtime-${entrypoint.name}`,\n // },\n };\n\n return {\n externals,\n optimization,\n\n plugins: [\n // Generate an asset manifest file with the following content:\n // - \"files\" key: Mapping of all asset filenames to their corresponding\n // output file so that tools can pick it up without having to parse\n // `index.html`\n // can be used to reconstruct the HTML if necessary\n // new WebpackManifestPlugin({\n // fileName: 'asset-manifest.json',\n // publicPath: 'public',\n // generate: (seed, files, entrypoints) => {\n // const manifestFiles = files.reduce((manifest, file) => {\n // manifest[file.name] = file.path;\n // return manifest;\n // }, seed);\n // const entrypointFiles = entrypoints.main.filter((fileName) => !fileName.endsWith('.map'));\n\n // // @ts-ignore - https://github.com/shellscape/webpack-manifest-plugin/issues/276\n // return {\n // files: manifestFiles,\n // entrypoints: entrypointFiles,\n // } as Record<string, string>;\n // },\n // }),\n // Generate a service worker script that will precache, and keep up to date,\n // the HTML & assets that are part of the webpack build.\n new WorkboxWebpackPlugin.GenerateSW({\n clientsClaim: true,\n exclude: [/\\.map$/, /asset-manifest\\.json$/],\n // importWorkboxFrom: 'cdn',\n navigateFallback: 'public/index.html',\n navigateFallbackDenylist: [\n // Exclude URLs starting with /_, as they're likely an API call\n new RegExp('^/_'),\n // Exclude any URLs whose last part seems to be a file extension\n // as they're likely a resource and not a SPA route.\n // URLs containing a \"?\" character won't be blacklisted as they're likely\n // a route with query params (e.g. auth callbacks).\n new RegExp('/[^/?]+\\\\.[^/]+$'),\n ],\n }),\n ].filter(Boolean),\n // Turn off performance processing because we utilize\n // our own hints via the FileSizeReporter\n performance: false,\n };\n}\n"]}
|
|
File without changes
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teambit/react",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.735",
|
|
4
4
|
"homepage": "https://bit.dev/teambit/react/react",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"componentId": {
|
|
7
7
|
"scope": "teambit.react",
|
|
8
8
|
"name": "react",
|
|
9
|
-
"version": "0.0.
|
|
9
|
+
"version": "0.0.735"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"react-error-boundary": "^3.0.0",
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
"camelcase": "6.2.0",
|
|
21
21
|
"expose-loader": "3.1.0",
|
|
22
22
|
"postcss-preset-env": "6.7.0",
|
|
23
|
+
"enhanced-resolve": "4.5.0",
|
|
23
24
|
"find-root": "1.1.0",
|
|
24
25
|
"css-minimizer-webpack-plugin": "3.0.2",
|
|
25
26
|
"terser-webpack-plugin": "5.2.0",
|
|
@@ -42,7 +43,7 @@
|
|
|
42
43
|
"@babel/preset-env": "7.12.17",
|
|
43
44
|
"react-error-overlay": "6.0.9",
|
|
44
45
|
"strip-ansi": "6.0.0",
|
|
45
|
-
"
|
|
46
|
+
"prerender-spa-plugin-next": "4.2.0",
|
|
46
47
|
"comment-json": "3.0.3",
|
|
47
48
|
"react-refresh": "0.10.0",
|
|
48
49
|
"@babel/runtime": "^7.12.18",
|
|
@@ -83,49 +84,50 @@
|
|
|
83
84
|
"@teambit/react.instructions.react.adding-compositions": "0.0.6",
|
|
84
85
|
"@teambit/react.instructions.react.adding-tests": "0.0.6",
|
|
85
86
|
"@teambit/design.ui.pages.standalone-not-found-page": "0.0.356",
|
|
86
|
-
"@teambit/preview": "0.0.
|
|
87
|
+
"@teambit/preview": "0.0.735",
|
|
87
88
|
"@teambit/react.ui.error-fallback": "0.0.111",
|
|
88
89
|
"@teambit/react.ui.loader-fallback": "0.0.89",
|
|
89
90
|
"@teambit/compositions.ui.hooks.use-composition": "0.0.163",
|
|
90
91
|
"@teambit/design.ui.tooltip": "0.0.352",
|
|
91
|
-
"@teambit/builder": "0.0.
|
|
92
|
-
"@teambit/bundler": "0.0.
|
|
93
|
-
"@teambit/compiler": "0.0.
|
|
92
|
+
"@teambit/builder": "0.0.735",
|
|
93
|
+
"@teambit/bundler": "0.0.735",
|
|
94
|
+
"@teambit/compiler": "0.0.735",
|
|
94
95
|
"@teambit/component.modules.component-url": "0.0.124",
|
|
95
|
-
"@teambit/component": "0.0.
|
|
96
|
-
"@teambit/envs": "0.0.
|
|
97
|
-
"@teambit/eslint": "0.0.
|
|
98
|
-
"@teambit/formatter": "0.0.
|
|
99
|
-
"@teambit/jest": "0.0.
|
|
100
|
-
"@teambit/linter": "0.0.
|
|
101
|
-
"@teambit/logger": "0.0.
|
|
102
|
-
"@teambit/pkg": "0.0.
|
|
103
|
-
"@teambit/prettier": "0.0.
|
|
96
|
+
"@teambit/component": "0.0.735",
|
|
97
|
+
"@teambit/envs": "0.0.735",
|
|
98
|
+
"@teambit/eslint": "0.0.735",
|
|
99
|
+
"@teambit/formatter": "0.0.286",
|
|
100
|
+
"@teambit/jest": "0.0.735",
|
|
101
|
+
"@teambit/linter": "0.0.735",
|
|
102
|
+
"@teambit/logger": "0.0.583",
|
|
103
|
+
"@teambit/pkg": "0.0.735",
|
|
104
|
+
"@teambit/prettier": "0.0.286",
|
|
104
105
|
"@teambit/react.ui.highlighter.component-metadata.bit-component-meta": "0.0.21",
|
|
105
|
-
"@teambit/schema": "0.0.
|
|
106
|
-
"@teambit/tester": "0.0.
|
|
107
|
-
"@teambit/typescript": "0.0.
|
|
108
|
-
"@teambit/webpack": "0.0.
|
|
109
|
-
"@teambit/workspace": "0.0.
|
|
110
|
-
"@teambit/application": "0.0.
|
|
111
|
-
"@teambit/cli": "0.0.
|
|
112
|
-
"@teambit/dependency-resolver": "0.0.
|
|
113
|
-
"@teambit/generator": "0.0.
|
|
114
|
-
"@teambit/graphql": "0.0.
|
|
106
|
+
"@teambit/schema": "0.0.735",
|
|
107
|
+
"@teambit/tester": "0.0.735",
|
|
108
|
+
"@teambit/typescript": "0.0.735",
|
|
109
|
+
"@teambit/webpack": "0.0.735",
|
|
110
|
+
"@teambit/workspace": "0.0.735",
|
|
111
|
+
"@teambit/application": "0.0.377",
|
|
112
|
+
"@teambit/cli": "0.0.491",
|
|
113
|
+
"@teambit/dependency-resolver": "0.0.735",
|
|
114
|
+
"@teambit/generator": "0.0.735",
|
|
115
|
+
"@teambit/graphql": "0.0.735",
|
|
115
116
|
"@teambit/react.ui.highlighter-provider": "0.0.189",
|
|
116
|
-
"@teambit/compositions": "0.0.
|
|
117
|
-
"@teambit/ui": "0.0.
|
|
118
|
-
"@teambit/react.eslint-config-bit-react": "0.0.
|
|
117
|
+
"@teambit/compositions": "0.0.735",
|
|
118
|
+
"@teambit/ui": "0.0.735",
|
|
119
|
+
"@teambit/react.eslint-config-bit-react": "0.0.565",
|
|
119
120
|
"@teambit/webpack.modules.generate-expose-loaders": "0.0.3",
|
|
120
121
|
"@teambit/webpack.modules.generate-externals": "0.0.3",
|
|
121
|
-
"@teambit/webpack.modules.config-mutator": "0.0.
|
|
122
|
+
"@teambit/webpack.modules.config-mutator": "0.0.138",
|
|
122
123
|
"@teambit/mdx.modules.mdx-loader": "0.0.489",
|
|
123
124
|
"@teambit/react.babel.bit-react-transformer": "0.0.501",
|
|
124
125
|
"@teambit/webpack.modules.generate-style-loaders": "0.0.103",
|
|
125
126
|
"@teambit/webpack.modules.style-regexps": "0.0.132",
|
|
126
127
|
"@teambit/component-id": "0.0.402",
|
|
127
128
|
"@teambit/toolbox.network.get-port": "0.0.113",
|
|
128
|
-
"@teambit/
|
|
129
|
+
"@teambit/react.modules.prerenderer-puppeteer": "0.0.2",
|
|
130
|
+
"@teambit/config": "0.0.504"
|
|
129
131
|
},
|
|
130
132
|
"devDependencies": {
|
|
131
133
|
"@types/react": "^17.0.8",
|
|
@@ -145,7 +147,7 @@
|
|
|
145
147
|
"@teambit/react.content.react-overview": "1.95.0"
|
|
146
148
|
},
|
|
147
149
|
"peerDependencies": {
|
|
148
|
-
"@teambit/legacy": "1.0.
|
|
150
|
+
"@teambit/legacy": "1.0.271",
|
|
149
151
|
"react-dom": "^16.8.0 || ^17.0.0",
|
|
150
152
|
"react": "^16.8.0 || ^17.0.0"
|
|
151
153
|
},
|
|
@@ -209,7 +211,7 @@
|
|
|
209
211
|
"@types/jest": "^26.0.0"
|
|
210
212
|
},
|
|
211
213
|
"peerDependencies": {
|
|
212
|
-
"@teambit/legacy": "1.0.
|
|
214
|
+
"@teambit/legacy": "1.0.271",
|
|
213
215
|
"react-dom": "^16.8.0 || ^17.0.0",
|
|
214
216
|
"react": "^16.8.0 || ^17.0.0"
|
|
215
217
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const compositions = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.react_react@0.0.
|
|
2
|
-
export const overview = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.react_react@0.0.
|
|
1
|
+
export const compositions = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.react_react@0.0.735/dist/react.composition.js')]
|
|
2
|
+
export const overview = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.react_react@0.0.735/dist/react.docs.mdx')]
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import camelcase from 'camelcase';
|
|
2
2
|
import 'expose-loader';
|
|
3
|
+
import { Logger } from '@teambit/logger';
|
|
3
4
|
import { generateExposeLoaders } from '@teambit/webpack.modules.generate-expose-loaders';
|
|
5
|
+
import { resolvePeerToFile } from './resolve-peer';
|
|
4
6
|
|
|
5
|
-
export function getExposedRules(peers: string[]) {
|
|
7
|
+
export function getExposedRules(peers: string[], logger: Logger, hostRootDir?: string) {
|
|
6
8
|
const loaderPath = require.resolve('expose-loader');
|
|
7
9
|
const depsEntries = peers.map((peer) => ({
|
|
8
|
-
path:
|
|
10
|
+
path: resolvePeerToFile(peer, logger, hostRootDir),
|
|
9
11
|
globalName: camelcase(peer.replace('@', '').replace('/', '-'), { pascalCase: true }),
|
|
10
12
|
}));
|
|
11
13
|
return generateExposeLoaders(depsEntries, { loaderPath });
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import fs, { realpathSync } from 'fs';
|
|
2
|
+
import { ResolverFactory, CachedInputFileSystem } from 'enhanced-resolve';
|
|
3
|
+
import findRoot from 'find-root';
|
|
4
|
+
import { Logger } from '@teambit/logger';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Get the package folder, and in case it's not found get the resolved file path
|
|
8
|
+
* @param peerName
|
|
9
|
+
* @returns
|
|
10
|
+
*/
|
|
11
|
+
export function resolvePeerToDirOrFile(peerName: string, logger: Logger, hostRootDir?: string): string | undefined {
|
|
12
|
+
let resolved;
|
|
13
|
+
try {
|
|
14
|
+
let options;
|
|
15
|
+
if (hostRootDir) {
|
|
16
|
+
options = {
|
|
17
|
+
// resolve the host root dir to its real location, as require.resolve is preserve symlink, so we get wrong result otherwise
|
|
18
|
+
paths: [realpathSync(hostRootDir), __dirname],
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
resolved = require.resolve(peerName, options);
|
|
22
|
+
const folder = findRoot(resolved);
|
|
23
|
+
return folder;
|
|
24
|
+
} catch (e) {
|
|
25
|
+
if (resolved) {
|
|
26
|
+
logger.warn(`Couldn't find root dir for "${peerName}" from path "${resolved}" to add it as webpack alias`);
|
|
27
|
+
} else {
|
|
28
|
+
logger.warn(`Couldn't resolve "${peerName}" to add it as webpack alias`);
|
|
29
|
+
}
|
|
30
|
+
return resolved;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Make sure to resolve the peer path correctly
|
|
36
|
+
* we first resolve it to its dir (to be aligned with the aliases transformer)
|
|
37
|
+
* Then we resolve it to specific file, using enhanced resolve to make sure we resolve it using the correct main fields order
|
|
38
|
+
* @param peer
|
|
39
|
+
*/
|
|
40
|
+
export function resolvePeerToFile(peer: string, logger: Logger, hostRootDir?: string) {
|
|
41
|
+
const dirOrFile = resolvePeerToDirOrFile(peer, logger, hostRootDir);
|
|
42
|
+
const resolver = createResolver();
|
|
43
|
+
const resolvedFile = resolver.resolveSync({}, '', dirOrFile);
|
|
44
|
+
return resolvedFile;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Generate a resolver that will read first the module field then the main field
|
|
49
|
+
* to make it compatible with webpack behavior
|
|
50
|
+
* @returns
|
|
51
|
+
*/
|
|
52
|
+
function createResolver() {
|
|
53
|
+
// create a resolver
|
|
54
|
+
const myResolver = ResolverFactory.createResolver({
|
|
55
|
+
fileSystem: new CachedInputFileSystem(fs, 4000),
|
|
56
|
+
useSyncFileSystemCalls: true,
|
|
57
|
+
mainFields: ['module', 'main'],
|
|
58
|
+
});
|
|
59
|
+
return myResolver;
|
|
60
|
+
}
|
package/webpack/transformers.ts
CHANGED
|
@@ -1,46 +1,37 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { WebpackConfigTransformContext } from '@teambit/webpack';
|
|
2
2
|
import { WebpackConfigMutator } from '@teambit/webpack.modules.config-mutator';
|
|
3
3
|
import { Logger } from '@teambit/logger';
|
|
4
|
+
import { getExposedRules } from './get-exposed-rules';
|
|
5
|
+
import { resolvePeerToDirOrFile } from './resolve-peer';
|
|
4
6
|
|
|
5
7
|
export function generateAddAliasesFromPeersTransformer(peers: string[], logger: Logger) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
acc
|
|
18
|
-
}
|
|
19
|
-
return acc;
|
|
20
|
-
}, {});
|
|
21
|
-
return (config: WebpackConfigMutator): WebpackConfigMutator => {
|
|
8
|
+
return (config: WebpackConfigMutator, context: WebpackConfigTransformContext): WebpackConfigMutator => {
|
|
9
|
+
const peerAliases = peers.reduce((acc, peerName) => {
|
|
10
|
+
// gets the correct module folder of the package.
|
|
11
|
+
// this allows us to resolve internal files, for example:
|
|
12
|
+
// node_modules/react-dom/test-utils
|
|
13
|
+
//
|
|
14
|
+
// we can't use require.resolve() because it resolves to a specific file.
|
|
15
|
+
// for example, if we used "react-dom": require.resolve("react-dom"),
|
|
16
|
+
// it would try to resolve "react-dom/test-utils" as:
|
|
17
|
+
// node_modules/react-dom/index.js/test-utils
|
|
18
|
+
acc[peerName] = resolvePeerToDirOrFile(peerName, logger, context.target?.hostRootDir);
|
|
19
|
+
return acc;
|
|
20
|
+
}, {});
|
|
22
21
|
config.addAliases(peerAliases);
|
|
23
22
|
return config;
|
|
24
23
|
};
|
|
25
24
|
}
|
|
26
25
|
|
|
27
26
|
/**
|
|
28
|
-
*
|
|
29
|
-
* @param
|
|
27
|
+
* Generate a transformer that expose all the peers as global via the expose loader
|
|
28
|
+
* @param peers
|
|
30
29
|
* @returns
|
|
31
30
|
*/
|
|
32
|
-
function
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
} catch (e) {
|
|
39
|
-
if (resolved) {
|
|
40
|
-
logger.warn(`Couldn't find root dir for "${peerName}" from path "${resolved}" to add it as webpack alias`);
|
|
41
|
-
} else {
|
|
42
|
-
logger.warn(`Couldn't resolve "${peerName}" to add it as webpack alias`);
|
|
43
|
-
}
|
|
44
|
-
return resolved;
|
|
45
|
-
}
|
|
31
|
+
export function generateExposePeersTransformer(peers: string[], logger: Logger) {
|
|
32
|
+
return (config: WebpackConfigMutator, context: WebpackConfigTransformContext): WebpackConfigMutator => {
|
|
33
|
+
const exposedRules = getExposedRules(peers, logger, context.target?.hostRootDir);
|
|
34
|
+
config.addModuleRules(exposedRules);
|
|
35
|
+
return config;
|
|
36
|
+
};
|
|
46
37
|
}
|