@teambit/workspace.modules.node-modules-linker 0.0.0-598ddc1cd9f365bfa60c2cb341589576d3477c6a

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.
@@ -0,0 +1,141 @@
1
+ import path from 'path';
2
+ import { Workspace } from '@teambit/workspace';
3
+ import { IssuesClasses, RelativeComponentsAuthoredEntry } from '@teambit/component-issues';
4
+ import { Component } from '@teambit/component';
5
+ import { ComponentID, ComponentIdList } from '@teambit/component-id';
6
+ import { pathJoinLinux, pathNormalizeToLinux, pathRelativeLinux, replacePackageName } from '@teambit/legacy.utils';
7
+ import { componentIdToPackageName } from '@teambit/pkg.modules.component-package-name';
8
+ import { DataToPersist, SourceFile } from '@teambit/component.sources';
9
+ import { ConsumerComponent } from '@teambit/legacy.consumer-component';
10
+
11
+ export type CodemodResult = {
12
+ id: ComponentID;
13
+ changedFiles: string[];
14
+ warnings?: string[];
15
+ };
16
+
17
+ export async function changeCodeFromRelativeToModulePaths(
18
+ workspace: Workspace,
19
+ bitIds: ComponentID[]
20
+ ): Promise<CodemodResult[]> {
21
+ const components = await loadComponents(workspace, bitIds);
22
+ const componentsWithRelativeIssues = components.filter(
23
+ (c) => c.state.issues && c.state.issues.getIssue(IssuesClasses.RelativeComponentsAuthored)
24
+ );
25
+ const dataToPersist = new DataToPersist();
26
+ const codemodResults = await Promise.all(
27
+ componentsWithRelativeIssues.map(async (component) => {
28
+ const { files, warnings } = await codemodComponent(workspace, component);
29
+ dataToPersist.addManyFiles(files);
30
+ return { id: component.id, changedFiles: files.map((f) => f.relative), warnings };
31
+ })
32
+ );
33
+ await dataToPersist.persistAllToFS();
34
+ const idsToReload = codemodResults.filter((c) => !c.warnings || c.warnings.length === 0).map((c) => c.id);
35
+ await reloadComponents(workspace, idsToReload);
36
+
37
+ return codemodResults.filter((c) => c.changedFiles.length || c.warnings);
38
+ }
39
+
40
+ async function reloadComponents(workspace: Workspace, compIds: ComponentID[]) {
41
+ workspace.clearAllComponentsCache();
42
+ if (!compIds.length) return;
43
+ const components = await loadComponents(workspace, compIds);
44
+ const componentsWithRelativeIssues = components.filter(
45
+ (c) => c.state.issues && c.state.issues.getIssue(IssuesClasses.RelativeComponentsAuthored)
46
+ );
47
+ if (componentsWithRelativeIssues.length) {
48
+ const failedComps = componentsWithRelativeIssues.map((c) => c.id.toString()).join(', ');
49
+ throw new Error(`failed rewiring the following components: ${failedComps}`);
50
+ }
51
+ }
52
+
53
+ async function loadComponents(workspace: Workspace, bitIds: ComponentID[]): Promise<Component[]> {
54
+ const componentsIds = bitIds.length ? ComponentIdList.fromArray(bitIds) : await workspace.listIds();
55
+ const components = await workspace.getMany(componentsIds);
56
+
57
+ return components;
58
+ }
59
+
60
+ async function codemodComponent(
61
+ workspace: Workspace,
62
+ component: Component
63
+ ): Promise<{ files: SourceFile[]; warnings?: string[] }> {
64
+ const issues = component.state.issues;
65
+ const files: SourceFile[] = [];
66
+ if (!issues || !issues.getIssue(IssuesClasses.RelativeComponentsAuthored)) return { files };
67
+ const warnings: string[] = [];
68
+ await Promise.all(
69
+ component.filesystem.files.map(async (file: SourceFile) => {
70
+ const relativeInstances = issues.getIssue(IssuesClasses.RelativeComponentsAuthored)?.data[
71
+ pathNormalizeToLinux(file.relative)
72
+ ];
73
+ if (!relativeInstances) return;
74
+ // @ts-ignore
75
+ const fileBefore = file.contents.toString() as string;
76
+ let newFileString = fileBefore;
77
+ await Promise.all(
78
+ relativeInstances.map(async (relativeEntry: RelativeComponentsAuthoredEntry) => {
79
+ const id = relativeEntry.componentId;
80
+ const requiredComponent = await workspace.get(id);
81
+ const consumerComp = requiredComponent.state._consumer as ConsumerComponent;
82
+ const packageName = componentIdToPackageName({ ...consumerComp, id });
83
+ const cssFamily = ['.css', '.scss', '.less', '.sass'];
84
+ const isCss = cssFamily.includes(file.extname);
85
+ const packageNameSupportCss = isCss ? `~${packageName}` : packageName;
86
+ const stringToReplace = getNameWithoutInternalPath(workspace, relativeEntry);
87
+ // @todo: the "dist" should be replaced by the compiler dist-dir.
88
+ // newFileString = replacePackageName(newFileString, stringToReplace, packageNameSupportCss, 'dist');
89
+ newFileString = replacePackageName(newFileString, stringToReplace, packageNameSupportCss);
90
+ })
91
+ );
92
+ if (fileBefore !== newFileString) {
93
+ // @ts-ignore
94
+ file.contents = Buffer.from(newFileString);
95
+ files.push(file);
96
+ }
97
+ })
98
+ );
99
+ return { files, warnings };
100
+ }
101
+
102
+ /**
103
+ * e.g.
104
+ * importSource: '../workspace/workspace.ui'
105
+ * sourceRelativePath: 'extensions/workspace/workspace.ui.tsx'
106
+ * rootDir in .bitmap: 'extensions/workspace'.
107
+ *
108
+ * expected to return "../workspace", as this is the path to the package root without the internal path.
109
+ *
110
+ * eventually, only this string is replaced by the new package-name and the internal-path part
111
+ * remains intact. ('../workspace/workspace.ui' => '@bit/workspace/workspace.ui').
112
+ */
113
+ function getNameWithoutInternalPath(workspace: Workspace, relativeEntry: RelativeComponentsAuthoredEntry): string {
114
+ const importSource = relativeEntry.importSource;
115
+ const componentMap = workspace.consumer.bitMap.getComponentIfExist(relativeEntry.componentId);
116
+ if (!componentMap) return importSource;
117
+ const rootDir = componentMap.rootDir;
118
+ if (!rootDir) return importSource;
119
+ const mainFile = pathJoinLinux(rootDir, componentMap.mainFile);
120
+ const filePathRelativeToWorkspace = relativeEntry.relativePath.sourceRelativePath;
121
+ if (filePathRelativeToWorkspace === mainFile) {
122
+ return importSource;
123
+ }
124
+ // the importSource is not the main-file but an internal file, remove the internal part.
125
+ const internalPath = pathRelativeLinux(rootDir, filePathRelativeToWorkspace);
126
+ const removeLastOccurrence = (str, toRemove) => str.replace(new RegExp(`/${toRemove}$`), '');
127
+ if (importSource.endsWith(internalPath)) {
128
+ return removeLastOccurrence(importSource, internalPath);
129
+ }
130
+ const internalPathNoExt = internalPath.replace(path.extname(internalPath), '');
131
+ if (importSource.endsWith(internalPathNoExt)) {
132
+ return removeLastOccurrence(importSource, internalPathNoExt);
133
+ }
134
+ const internalPathNoIndex = removeLastOccurrence(internalPathNoExt, 'index');
135
+ if (importSource.endsWith(internalPathNoIndex)) {
136
+ return removeLastOccurrence(importSource, internalPathNoIndex);
137
+ }
138
+
139
+ // unable to find anything useful. just return the importSource.
140
+ return importSource;
141
+ }
@@ -0,0 +1,8 @@
1
+ import { Workspace } from '@teambit/workspace';
2
+ import { ComponentID } from '@teambit/component-id';
3
+ export type CodemodResult = {
4
+ id: ComponentID;
5
+ changedFiles: string[];
6
+ warnings?: string[];
7
+ };
8
+ export declare function changeCodeFromRelativeToModulePaths(workspace: Workspace, bitIds: ComponentID[]): Promise<CodemodResult[]>;
@@ -0,0 +1,168 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.changeCodeFromRelativeToModulePaths = changeCodeFromRelativeToModulePaths;
7
+ function _path() {
8
+ const data = _interopRequireDefault(require("path"));
9
+ _path = function () {
10
+ return data;
11
+ };
12
+ return data;
13
+ }
14
+ function _componentIssues() {
15
+ const data = require("@teambit/component-issues");
16
+ _componentIssues = function () {
17
+ return data;
18
+ };
19
+ return data;
20
+ }
21
+ function _componentId() {
22
+ const data = require("@teambit/component-id");
23
+ _componentId = function () {
24
+ return data;
25
+ };
26
+ return data;
27
+ }
28
+ function _legacy() {
29
+ const data = require("@teambit/legacy.utils");
30
+ _legacy = function () {
31
+ return data;
32
+ };
33
+ return data;
34
+ }
35
+ function _pkgModules() {
36
+ const data = require("@teambit/pkg.modules.component-package-name");
37
+ _pkgModules = function () {
38
+ return data;
39
+ };
40
+ return data;
41
+ }
42
+ function _component() {
43
+ const data = require("@teambit/component.sources");
44
+ _component = function () {
45
+ return data;
46
+ };
47
+ return data;
48
+ }
49
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
50
+ async function changeCodeFromRelativeToModulePaths(workspace, bitIds) {
51
+ const components = await loadComponents(workspace, bitIds);
52
+ const componentsWithRelativeIssues = components.filter(c => c.state.issues && c.state.issues.getIssue(_componentIssues().IssuesClasses.RelativeComponentsAuthored));
53
+ const dataToPersist = new (_component().DataToPersist)();
54
+ const codemodResults = await Promise.all(componentsWithRelativeIssues.map(async component => {
55
+ const {
56
+ files,
57
+ warnings
58
+ } = await codemodComponent(workspace, component);
59
+ dataToPersist.addManyFiles(files);
60
+ return {
61
+ id: component.id,
62
+ changedFiles: files.map(f => f.relative),
63
+ warnings
64
+ };
65
+ }));
66
+ await dataToPersist.persistAllToFS();
67
+ const idsToReload = codemodResults.filter(c => !c.warnings || c.warnings.length === 0).map(c => c.id);
68
+ await reloadComponents(workspace, idsToReload);
69
+ return codemodResults.filter(c => c.changedFiles.length || c.warnings);
70
+ }
71
+ async function reloadComponents(workspace, compIds) {
72
+ workspace.clearAllComponentsCache();
73
+ if (!compIds.length) return;
74
+ const components = await loadComponents(workspace, compIds);
75
+ const componentsWithRelativeIssues = components.filter(c => c.state.issues && c.state.issues.getIssue(_componentIssues().IssuesClasses.RelativeComponentsAuthored));
76
+ if (componentsWithRelativeIssues.length) {
77
+ const failedComps = componentsWithRelativeIssues.map(c => c.id.toString()).join(', ');
78
+ throw new Error(`failed rewiring the following components: ${failedComps}`);
79
+ }
80
+ }
81
+ async function loadComponents(workspace, bitIds) {
82
+ const componentsIds = bitIds.length ? _componentId().ComponentIdList.fromArray(bitIds) : await workspace.listIds();
83
+ const components = await workspace.getMany(componentsIds);
84
+ return components;
85
+ }
86
+ async function codemodComponent(workspace, component) {
87
+ const issues = component.state.issues;
88
+ const files = [];
89
+ if (!issues || !issues.getIssue(_componentIssues().IssuesClasses.RelativeComponentsAuthored)) return {
90
+ files
91
+ };
92
+ const warnings = [];
93
+ await Promise.all(component.filesystem.files.map(async file => {
94
+ const relativeInstances = issues.getIssue(_componentIssues().IssuesClasses.RelativeComponentsAuthored)?.data[(0, _legacy().pathNormalizeToLinux)(file.relative)];
95
+ if (!relativeInstances) return;
96
+ // @ts-ignore
97
+ const fileBefore = file.contents.toString();
98
+ let newFileString = fileBefore;
99
+ await Promise.all(relativeInstances.map(async relativeEntry => {
100
+ const id = relativeEntry.componentId;
101
+ const requiredComponent = await workspace.get(id);
102
+ const consumerComp = requiredComponent.state._consumer;
103
+ const packageName = (0, _pkgModules().componentIdToPackageName)({
104
+ ...consumerComp,
105
+ id
106
+ });
107
+ const cssFamily = ['.css', '.scss', '.less', '.sass'];
108
+ const isCss = cssFamily.includes(file.extname);
109
+ const packageNameSupportCss = isCss ? `~${packageName}` : packageName;
110
+ const stringToReplace = getNameWithoutInternalPath(workspace, relativeEntry);
111
+ // @todo: the "dist" should be replaced by the compiler dist-dir.
112
+ // newFileString = replacePackageName(newFileString, stringToReplace, packageNameSupportCss, 'dist');
113
+ newFileString = (0, _legacy().replacePackageName)(newFileString, stringToReplace, packageNameSupportCss);
114
+ }));
115
+ if (fileBefore !== newFileString) {
116
+ // @ts-ignore
117
+ file.contents = Buffer.from(newFileString);
118
+ files.push(file);
119
+ }
120
+ }));
121
+ return {
122
+ files,
123
+ warnings
124
+ };
125
+ }
126
+
127
+ /**
128
+ * e.g.
129
+ * importSource: '../workspace/workspace.ui'
130
+ * sourceRelativePath: 'extensions/workspace/workspace.ui.tsx'
131
+ * rootDir in .bitmap: 'extensions/workspace'.
132
+ *
133
+ * expected to return "../workspace", as this is the path to the package root without the internal path.
134
+ *
135
+ * eventually, only this string is replaced by the new package-name and the internal-path part
136
+ * remains intact. ('../workspace/workspace.ui' => '@bit/workspace/workspace.ui').
137
+ */
138
+ function getNameWithoutInternalPath(workspace, relativeEntry) {
139
+ const importSource = relativeEntry.importSource;
140
+ const componentMap = workspace.consumer.bitMap.getComponentIfExist(relativeEntry.componentId);
141
+ if (!componentMap) return importSource;
142
+ const rootDir = componentMap.rootDir;
143
+ if (!rootDir) return importSource;
144
+ const mainFile = (0, _legacy().pathJoinLinux)(rootDir, componentMap.mainFile);
145
+ const filePathRelativeToWorkspace = relativeEntry.relativePath.sourceRelativePath;
146
+ if (filePathRelativeToWorkspace === mainFile) {
147
+ return importSource;
148
+ }
149
+ // the importSource is not the main-file but an internal file, remove the internal part.
150
+ const internalPath = (0, _legacy().pathRelativeLinux)(rootDir, filePathRelativeToWorkspace);
151
+ const removeLastOccurrence = (str, toRemove) => str.replace(new RegExp(`/${toRemove}$`), '');
152
+ if (importSource.endsWith(internalPath)) {
153
+ return removeLastOccurrence(importSource, internalPath);
154
+ }
155
+ const internalPathNoExt = internalPath.replace(_path().default.extname(internalPath), '');
156
+ if (importSource.endsWith(internalPathNoExt)) {
157
+ return removeLastOccurrence(importSource, internalPathNoExt);
158
+ }
159
+ const internalPathNoIndex = removeLastOccurrence(internalPathNoExt, 'index');
160
+ if (importSource.endsWith(internalPathNoIndex)) {
161
+ return removeLastOccurrence(importSource, internalPathNoIndex);
162
+ }
163
+
164
+ // unable to find anything useful. just return the importSource.
165
+ return importSource;
166
+ }
167
+
168
+ //# sourceMappingURL=codemod-components.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_path","data","_interopRequireDefault","require","_componentIssues","_componentId","_legacy","_pkgModules","_component","e","__esModule","default","changeCodeFromRelativeToModulePaths","workspace","bitIds","components","loadComponents","componentsWithRelativeIssues","filter","c","state","issues","getIssue","IssuesClasses","RelativeComponentsAuthored","dataToPersist","DataToPersist","codemodResults","Promise","all","map","component","files","warnings","codemodComponent","addManyFiles","id","changedFiles","f","relative","persistAllToFS","idsToReload","length","reloadComponents","compIds","clearAllComponentsCache","failedComps","toString","join","Error","componentsIds","ComponentIdList","fromArray","listIds","getMany","filesystem","file","relativeInstances","pathNormalizeToLinux","fileBefore","contents","newFileString","relativeEntry","componentId","requiredComponent","get","consumerComp","_consumer","packageName","componentIdToPackageName","cssFamily","isCss","includes","extname","packageNameSupportCss","stringToReplace","getNameWithoutInternalPath","replacePackageName","Buffer","from","push","importSource","componentMap","consumer","bitMap","getComponentIfExist","rootDir","mainFile","pathJoinLinux","filePathRelativeToWorkspace","relativePath","sourceRelativePath","internalPath","pathRelativeLinux","removeLastOccurrence","str","toRemove","replace","RegExp","endsWith","internalPathNoExt","path","internalPathNoIndex"],"sources":["codemod-components.ts"],"sourcesContent":["import path from 'path';\nimport { Workspace } from '@teambit/workspace';\nimport { IssuesClasses, RelativeComponentsAuthoredEntry } from '@teambit/component-issues';\nimport { Component } from '@teambit/component';\nimport { ComponentID, ComponentIdList } from '@teambit/component-id';\nimport { pathJoinLinux, pathNormalizeToLinux, pathRelativeLinux, replacePackageName } from '@teambit/legacy.utils';\nimport { componentIdToPackageName } from '@teambit/pkg.modules.component-package-name';\nimport { DataToPersist, SourceFile } from '@teambit/component.sources';\nimport { ConsumerComponent } from '@teambit/legacy.consumer-component';\n\nexport type CodemodResult = {\n id: ComponentID;\n changedFiles: string[];\n warnings?: string[];\n};\n\nexport async function changeCodeFromRelativeToModulePaths(\n workspace: Workspace,\n bitIds: ComponentID[]\n): Promise<CodemodResult[]> {\n const components = await loadComponents(workspace, bitIds);\n const componentsWithRelativeIssues = components.filter(\n (c) => c.state.issues && c.state.issues.getIssue(IssuesClasses.RelativeComponentsAuthored)\n );\n const dataToPersist = new DataToPersist();\n const codemodResults = await Promise.all(\n componentsWithRelativeIssues.map(async (component) => {\n const { files, warnings } = await codemodComponent(workspace, component);\n dataToPersist.addManyFiles(files);\n return { id: component.id, changedFiles: files.map((f) => f.relative), warnings };\n })\n );\n await dataToPersist.persistAllToFS();\n const idsToReload = codemodResults.filter((c) => !c.warnings || c.warnings.length === 0).map((c) => c.id);\n await reloadComponents(workspace, idsToReload);\n\n return codemodResults.filter((c) => c.changedFiles.length || c.warnings);\n}\n\nasync function reloadComponents(workspace: Workspace, compIds: ComponentID[]) {\n workspace.clearAllComponentsCache();\n if (!compIds.length) return;\n const components = await loadComponents(workspace, compIds);\n const componentsWithRelativeIssues = components.filter(\n (c) => c.state.issues && c.state.issues.getIssue(IssuesClasses.RelativeComponentsAuthored)\n );\n if (componentsWithRelativeIssues.length) {\n const failedComps = componentsWithRelativeIssues.map((c) => c.id.toString()).join(', ');\n throw new Error(`failed rewiring the following components: ${failedComps}`);\n }\n}\n\nasync function loadComponents(workspace: Workspace, bitIds: ComponentID[]): Promise<Component[]> {\n const componentsIds = bitIds.length ? ComponentIdList.fromArray(bitIds) : await workspace.listIds();\n const components = await workspace.getMany(componentsIds);\n\n return components;\n}\n\nasync function codemodComponent(\n workspace: Workspace,\n component: Component\n): Promise<{ files: SourceFile[]; warnings?: string[] }> {\n const issues = component.state.issues;\n const files: SourceFile[] = [];\n if (!issues || !issues.getIssue(IssuesClasses.RelativeComponentsAuthored)) return { files };\n const warnings: string[] = [];\n await Promise.all(\n component.filesystem.files.map(async (file: SourceFile) => {\n const relativeInstances = issues.getIssue(IssuesClasses.RelativeComponentsAuthored)?.data[\n pathNormalizeToLinux(file.relative)\n ];\n if (!relativeInstances) return;\n // @ts-ignore\n const fileBefore = file.contents.toString() as string;\n let newFileString = fileBefore;\n await Promise.all(\n relativeInstances.map(async (relativeEntry: RelativeComponentsAuthoredEntry) => {\n const id = relativeEntry.componentId;\n const requiredComponent = await workspace.get(id);\n const consumerComp = requiredComponent.state._consumer as ConsumerComponent;\n const packageName = componentIdToPackageName({ ...consumerComp, id });\n const cssFamily = ['.css', '.scss', '.less', '.sass'];\n const isCss = cssFamily.includes(file.extname);\n const packageNameSupportCss = isCss ? `~${packageName}` : packageName;\n const stringToReplace = getNameWithoutInternalPath(workspace, relativeEntry);\n // @todo: the \"dist\" should be replaced by the compiler dist-dir.\n // newFileString = replacePackageName(newFileString, stringToReplace, packageNameSupportCss, 'dist');\n newFileString = replacePackageName(newFileString, stringToReplace, packageNameSupportCss);\n })\n );\n if (fileBefore !== newFileString) {\n // @ts-ignore\n file.contents = Buffer.from(newFileString);\n files.push(file);\n }\n })\n );\n return { files, warnings };\n}\n\n/**\n * e.g.\n * importSource: '../workspace/workspace.ui'\n * sourceRelativePath: 'extensions/workspace/workspace.ui.tsx'\n * rootDir in .bitmap: 'extensions/workspace'.\n *\n * expected to return \"../workspace\", as this is the path to the package root without the internal path.\n *\n * eventually, only this string is replaced by the new package-name and the internal-path part\n * remains intact. ('../workspace/workspace.ui' => '@bit/workspace/workspace.ui').\n */\nfunction getNameWithoutInternalPath(workspace: Workspace, relativeEntry: RelativeComponentsAuthoredEntry): string {\n const importSource = relativeEntry.importSource;\n const componentMap = workspace.consumer.bitMap.getComponentIfExist(relativeEntry.componentId);\n if (!componentMap) return importSource;\n const rootDir = componentMap.rootDir;\n if (!rootDir) return importSource;\n const mainFile = pathJoinLinux(rootDir, componentMap.mainFile);\n const filePathRelativeToWorkspace = relativeEntry.relativePath.sourceRelativePath;\n if (filePathRelativeToWorkspace === mainFile) {\n return importSource;\n }\n // the importSource is not the main-file but an internal file, remove the internal part.\n const internalPath = pathRelativeLinux(rootDir, filePathRelativeToWorkspace);\n const removeLastOccurrence = (str, toRemove) => str.replace(new RegExp(`/${toRemove}$`), '');\n if (importSource.endsWith(internalPath)) {\n return removeLastOccurrence(importSource, internalPath);\n }\n const internalPathNoExt = internalPath.replace(path.extname(internalPath), '');\n if (importSource.endsWith(internalPathNoExt)) {\n return removeLastOccurrence(importSource, internalPathNoExt);\n }\n const internalPathNoIndex = removeLastOccurrence(internalPathNoExt, 'index');\n if (importSource.endsWith(internalPathNoIndex)) {\n return removeLastOccurrence(importSource, internalPathNoIndex);\n }\n\n // unable to find anything useful. just return the importSource.\n return importSource;\n}\n"],"mappings":";;;;;;AAAA,SAAAA,MAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAH,KAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,SAAAG,iBAAA;EAAA,MAAAH,IAAA,GAAAE,OAAA;EAAAC,gBAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,SAAAI,aAAA;EAAA,MAAAJ,IAAA,GAAAE,OAAA;EAAAE,YAAA,YAAAA,CAAA;IAAA,OAAAJ,IAAA;EA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AY,CAACK,QAAQ,CAAC;EAC9D,MAAME,2BAA2B,GAAG3B,aAAa,CAAC4B,YAAY,CAACC,kBAAkB;EACjF,IAAIF,2BAA2B,KAAKF,QAAQ,EAAE;IAC5C,OAAON,YAAY;EACrB;EACA;EACA,MAAMW,YAAY,GAAG,IAAAC,2BAAiB,EAACP,OAAO,EAAEG,2BAA2B,CAAC;EAC5E,MAAMK,oBAAoB,GAAGA,CAACC,GAAG,EAAEC,QAAQ,KAAKD,GAAG,CAACE,OAAO,CAAC,IAAIC,MAAM,CAAC,IAAIF,QAAQ,GAAG,CAAC,EAAE,EAAE,CAAC;EAC5F,IAAIf,YAAY,CAACkB,QAAQ,CAACP,YAAY,CAAC,EAAE;IACvC,OAAOE,oBAAoB,CAACb,YAAY,EAAEW,YAAY,CAAC;EACzD;EACA,MAAMQ,iBAAiB,GAAGR,YAAY,CAACK,OAAO,CAACI,eAAI,CAAC5B,OAAO,CAACmB,YAAY,CAAC,EAAE,EAAE,CAAC;EAC9E,IAAIX,YAAY,CAACkB,QAAQ,CAACC,iBAAiB,CAAC,EAAE;IAC5C,OAAON,oBAAoB,CAACb,YAAY,EAAEmB,iBAAiB,CAAC;EAC9D;EACA,MAAME,mBAAmB,GAAGR,oBAAoB,CAACM,iBAAiB,EAAE,OAAO,CAAC;EAC5E,IAAInB,YAAY,CAACkB,QAAQ,CAACG,mBAAmB,CAAC,EAAE;IAC9C,OAAOR,oBAAoB,CAACb,YAAY,EAAEqB,mBAAmB,CAAC;EAChE;;EAEA;EACA,OAAOrB,YAAY;AACrB","ignoreList":[]}
@@ -0,0 +1,3 @@
1
+ export { NodeModulesLinksResult, linkToNodeModulesByIds, linkToNodeModulesWithCodemod, linkToNodeModulesByComponents, removeLinksFromNodeModules, } from './node-modules-linker';
2
+ export { PackageJsonTransformer } from './package-json-transformer';
3
+ export type { CodemodResult } from './codemod-components';
package/dist/index.js ADDED
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "NodeModulesLinksResult", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _nodeModulesLinker().NodeModulesLinksResult;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "PackageJsonTransformer", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _packageJsonTransformer().PackageJsonTransformer;
16
+ }
17
+ });
18
+ Object.defineProperty(exports, "linkToNodeModulesByComponents", {
19
+ enumerable: true,
20
+ get: function () {
21
+ return _nodeModulesLinker().linkToNodeModulesByComponents;
22
+ }
23
+ });
24
+ Object.defineProperty(exports, "linkToNodeModulesByIds", {
25
+ enumerable: true,
26
+ get: function () {
27
+ return _nodeModulesLinker().linkToNodeModulesByIds;
28
+ }
29
+ });
30
+ Object.defineProperty(exports, "linkToNodeModulesWithCodemod", {
31
+ enumerable: true,
32
+ get: function () {
33
+ return _nodeModulesLinker().linkToNodeModulesWithCodemod;
34
+ }
35
+ });
36
+ Object.defineProperty(exports, "removeLinksFromNodeModules", {
37
+ enumerable: true,
38
+ get: function () {
39
+ return _nodeModulesLinker().removeLinksFromNodeModules;
40
+ }
41
+ });
42
+ function _nodeModulesLinker() {
43
+ const data = require("./node-modules-linker");
44
+ _nodeModulesLinker = function () {
45
+ return data;
46
+ };
47
+ return data;
48
+ }
49
+ function _packageJsonTransformer() {
50
+ const data = require("./package-json-transformer");
51
+ _packageJsonTransformer = function () {
52
+ return data;
53
+ };
54
+ return data;
55
+ }
56
+
57
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_nodeModulesLinker","data","require","_packageJsonTransformer"],"sources":["index.ts"],"sourcesContent":["export {\n NodeModulesLinksResult,\n linkToNodeModulesByIds,\n linkToNodeModulesWithCodemod,\n linkToNodeModulesByComponents,\n removeLinksFromNodeModules,\n} from './node-modules-linker';\n\nexport { PackageJsonTransformer } from './package-json-transformer';\n\nexport type { CodemodResult } from './codemod-components';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAAA,mBAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,kBAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAQA,SAAAE,wBAAA;EAAA,MAAAF,IAAA,GAAAC,OAAA;EAAAC,uBAAA,YAAAA,CAAA;IAAA,OAAAF,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA","ignoreList":[]}
@@ -0,0 +1,72 @@
1
+ import { ComponentID } from '@teambit/component-id';
2
+ import { BitMap } from '@teambit/legacy.bit-map';
3
+ import { ConsumerComponent } from '@teambit/legacy.consumer-component';
4
+ import { PackageJsonFile, DataToPersist } from '@teambit/component.sources';
5
+ import { Consumer } from '@teambit/legacy.consumer';
6
+ import { PathOsBasedAbsolute } from '@teambit/toolbox.path.path';
7
+ import { Workspace } from '@teambit/workspace';
8
+ import { Component } from '@teambit/component';
9
+ type LinkDetail = {
10
+ from: string;
11
+ to: string;
12
+ existsBefore: boolean;
13
+ };
14
+ export type NodeModulesLinksResult = {
15
+ id: ComponentID;
16
+ bound: LinkDetail[];
17
+ };
18
+ /**
19
+ * link given components to node_modules, so it's possible to use absolute link instead of relative
20
+ * for example, require('@bit/remote-scope.bar.foo)
21
+ */
22
+ export default class NodeModuleLinker {
23
+ private components;
24
+ private workspace;
25
+ consumer: Consumer;
26
+ bitMap: BitMap;
27
+ dataToPersist: DataToPersist;
28
+ existingLinks: NodeModulesLinksResult[];
29
+ packageJsonCreated: boolean;
30
+ constructor(components: Component[], workspace: Workspace);
31
+ link(): Promise<NodeModulesLinksResult[]>;
32
+ getLinks(): Promise<DataToPersist>;
33
+ private addLinkResult;
34
+ getLinksResults(): NodeModulesLinksResult[];
35
+ _getDefaultScope(component?: ConsumerComponent): string | undefined | null;
36
+ /**
37
+ * even when an authored component has rootDir, we can't just symlink that rootDir to
38
+ * node_modules/rootDir. it could work only when the main-file is index.js, not for other cases.
39
+ * node expects the module inside node_modules to have either package.json with valid "main"
40
+ * property or an index.js file. this main property can't be relative.
41
+ */
42
+ _populateComponentsLinks(component: Component): Promise<void>;
43
+ private symlinkComponentDir;
44
+ /**
45
+ * Removing existing links root (the package path) - to handle cases it was linked by package manager for example
46
+ * this makes sure we are not affecting other places (like package manager cache) we shouldn't touch
47
+ * If you have a case when this deletes something created by the package manager and it's not the desired behavior,
48
+ * do not delete this code, but make sure the package manger nest the installed version into it's dependent
49
+ * @param component
50
+ */
51
+ _deleteExistingLinksRootIfSymlink(linkPath: string): undefined;
52
+ /**
53
+ * create package.json on node_modules/@bit/component-name/package.json with a property 'main'
54
+ * pointing to the component's main file.
55
+ * It is needed for Authored components only.
56
+ * Since an authored component doesn't have rootDir, it's impossible to symlink to the component directory.
57
+ * It makes it easier for Author to use absolute syntax between their own components.
58
+ */
59
+ private createPackageJson;
60
+ /**
61
+ * these are changes made by aspects
62
+ */
63
+ _applyTransformers(component: Component, packageJson: PackageJsonFile): Promise<void>;
64
+ }
65
+ export declare function linkToNodeModulesWithCodemod(workspace: Workspace, bitIds: ComponentID[], changeRelativeToModulePaths: boolean): Promise<{
66
+ linksResults: NodeModulesLinksResult[];
67
+ codemodResults: any;
68
+ }>;
69
+ export declare function linkToNodeModulesByIds(workspace: Workspace, componentsIds: ComponentID[], loadFromScope?: boolean): Promise<NodeModulesLinksResult[]>;
70
+ export declare function linkToNodeModulesByComponents(components: Component[], workspace: Workspace): Promise<NodeModulesLinksResult[]>;
71
+ export declare function removeLinksFromNodeModules(component: Component, workspace: Workspace, files: PathOsBasedAbsolute[]): Promise<void>;
72
+ export {};