@dittowords/cli 4.4.0 → 4.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/actions/install-node-dependencies/action.yml +24 -0
- package/.github/workflows/required-checks.yml +24 -0
- package/__mocks__/fs.js +2 -0
- package/bin/__mocks__/api.js +48 -0
- package/bin/__mocks__/api.js.map +1 -0
- package/bin/config.js +6 -4
- package/bin/config.js.map +1 -1
- package/bin/config.test.js +4 -3
- package/bin/config.test.js.map +1 -1
- package/bin/consts.js +19 -29
- package/bin/consts.js.map +1 -1
- package/bin/generate-suggestions.js +68 -58
- package/bin/generate-suggestions.js.map +1 -1
- package/bin/generate-suggestions.test.js +24 -13
- package/bin/generate-suggestions.test.js.map +1 -1
- package/bin/http/__mocks__/fetchComponentFolders.js +71 -0
- package/bin/http/__mocks__/fetchComponentFolders.js.map +1 -0
- package/bin/http/__mocks__/fetchComponents.js +73 -0
- package/bin/http/__mocks__/fetchComponents.js.map +1 -0
- package/bin/http/__mocks__/fetchVariants.js +71 -0
- package/bin/http/__mocks__/fetchVariants.js.map +1 -0
- package/bin/http/fetchComponentFolders.js +4 -4
- package/bin/http/fetchComponentFolders.js.map +1 -1
- package/bin/http/fetchComponents.js +4 -4
- package/bin/http/fetchComponents.js.map +1 -1
- package/bin/http/fetchVariants.js +2 -2
- package/bin/http/fetchVariants.js.map +1 -1
- package/bin/http/http.test.js +159 -0
- package/bin/http/http.test.js.map +1 -0
- package/bin/http/importComponents.js +9 -2
- package/bin/http/importComponents.js.map +1 -1
- package/bin/init/project.test.js +5 -28
- package/bin/init/project.test.js.map +1 -1
- package/bin/init/token.js +72 -27
- package/bin/init/token.js.map +1 -1
- package/bin/init/token.test.js +87 -9
- package/bin/init/token.test.js.map +1 -1
- package/bin/pull-lib.test.js +379 -0
- package/bin/pull-lib.test.js.map +1 -0
- package/bin/pull.js +13 -5
- package/bin/pull.js.map +1 -1
- package/bin/pull.test.js +100 -289
- package/bin/pull.test.js.map +1 -1
- package/bin/replace.js +22 -6
- package/bin/replace.js.map +1 -1
- package/bin/replace.test.js +53 -11
- package/bin/replace.test.js.map +1 -1
- package/bin/types.js +2 -2
- package/bin/types.js.map +1 -1
- package/bin/utils/determineModuleType.js +6 -7
- package/bin/utils/determineModuleType.js.map +1 -1
- package/bin/utils/determineModuleType.test.js +60 -0
- package/bin/utils/determineModuleType.test.js.map +1 -0
- package/bin/utils/getSelectedProjects.js +5 -5
- package/bin/utils/getSelectedProjects.js.map +1 -1
- package/bin/utils/quit.js +3 -3
- package/bin/utils/quit.js.map +1 -1
- package/jest.config.ts +16 -0
- package/lib/__mocks__/api.ts +12 -0
- package/lib/config.test.ts +3 -1
- package/lib/config.ts +4 -2
- package/lib/consts.ts +19 -17
- package/lib/generate-suggestions.test.ts +23 -11
- package/lib/generate-suggestions.ts +89 -79
- package/lib/http/__mocks__/fetchComponentFolders.ts +23 -0
- package/lib/http/__mocks__/fetchComponents.ts +24 -0
- package/lib/http/__mocks__/fetchVariants.ts +21 -0
- package/lib/http/fetchComponentFolders.ts +6 -4
- package/lib/http/fetchComponents.ts +5 -3
- package/lib/http/fetchVariants.ts +14 -3
- package/lib/http/http.test.ts +122 -0
- package/lib/http/importComponents.ts +8 -0
- package/lib/init/project.test.ts +4 -27
- package/lib/init/token.test.ts +55 -7
- package/lib/init/token.ts +76 -27
- package/lib/pull-lib.test.ts +367 -0
- package/lib/pull.test.ts +97 -310
- package/lib/pull.ts +11 -3
- package/lib/replace.test.ts +46 -10
- package/lib/replace.ts +20 -3
- package/lib/types.ts +5 -0
- package/lib/utils/determineModuleType.test.ts +48 -0
- package/lib/utils/determineModuleType.ts +4 -6
- package/lib/utils/getSelectedProjects.ts +3 -3
- package/lib/utils/quit.ts +1 -1
- package/package.json +4 -3
- package/jest.config.js +0 -6
package/bin/replace.test.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="8d2eb72b-d2d6-5847-b480-cd39f4da1f7e")}catch(e){}}();
|
|
3
3
|
|
|
4
4
|
var __create = Object.create;
|
|
5
5
|
var __defProp = Object.defineProperty;
|
|
@@ -43,18 +43,31 @@ var __async = (__this, __arguments, generator) => {
|
|
|
43
43
|
step((generator = generator.apply(__this, __arguments)).next());
|
|
44
44
|
});
|
|
45
45
|
};
|
|
46
|
-
var
|
|
46
|
+
var import_fs = __toESM(require("fs"));
|
|
47
47
|
var import_replace = require("./replace");
|
|
48
|
+
jest.mock("fs");
|
|
48
49
|
function createTempJSXFile(content) {
|
|
49
50
|
return __async(this, null, function* () {
|
|
50
|
-
const tempFile = "tempFile.jsx";
|
|
51
|
-
yield
|
|
51
|
+
const tempFile = "/tempFile.jsx";
|
|
52
|
+
yield new Promise((resolve, reject) => {
|
|
53
|
+
try {
|
|
54
|
+
import_fs.default.writeFile(tempFile, content, resolve);
|
|
55
|
+
} catch (e) {
|
|
56
|
+
reject(e);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
52
59
|
return tempFile;
|
|
53
60
|
});
|
|
54
61
|
}
|
|
55
62
|
function deleteTempFile(filePath) {
|
|
56
63
|
return __async(this, null, function* () {
|
|
57
|
-
yield
|
|
64
|
+
yield new Promise((resolve, reject) => {
|
|
65
|
+
try {
|
|
66
|
+
import_fs.default.unlink(filePath, resolve);
|
|
67
|
+
} catch (e) {
|
|
68
|
+
reject(e);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
58
71
|
});
|
|
59
72
|
}
|
|
60
73
|
describe("parseOptions", () => {
|
|
@@ -97,14 +110,22 @@ describe("parseOptions", () => {
|
|
|
97
110
|
});
|
|
98
111
|
describe("replaceJSXTextInFile", () => {
|
|
99
112
|
afterEach(() => __async(exports, null, function* () {
|
|
100
|
-
yield deleteTempFile("tempFile.jsx");
|
|
113
|
+
yield deleteTempFile("/tempFile.jsx");
|
|
101
114
|
}));
|
|
102
115
|
test("should replace JSX text with a DittoComponent", () => __async(exports, null, function* () {
|
|
103
116
|
const tempFile = yield createTempJSXFile("<div>Hello, world</div>");
|
|
104
117
|
const searchString = "world";
|
|
105
118
|
const replaceWith = "some-id";
|
|
106
119
|
yield (0, import_replace.replaceJSXTextInFile)(tempFile, { searchString, replaceWith }, {});
|
|
107
|
-
const transformedCode = yield
|
|
120
|
+
const transformedCode = yield new Promise((resolve, reject) => {
|
|
121
|
+
import_fs.default.readFile(tempFile, "utf-8", (error, data) => {
|
|
122
|
+
if (error) {
|
|
123
|
+
reject(error);
|
|
124
|
+
} else {
|
|
125
|
+
resolve(data);
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
});
|
|
108
129
|
expect(transformedCode).toContain(
|
|
109
130
|
`<div>Hello, <DittoComponent componentId="${replaceWith}" /></div>`
|
|
110
131
|
);
|
|
@@ -123,7 +144,14 @@ describe("replaceJSXTextInFile", () => {
|
|
|
123
144
|
{ searchString, replaceWith },
|
|
124
145
|
{ lineNumbers: [3] }
|
|
125
146
|
);
|
|
126
|
-
const transformedCode = yield
|
|
147
|
+
const transformedCode = yield new Promise(
|
|
148
|
+
(resolve, reject) => import_fs.default.readFile(tempFile, "utf-8", (error, data) => {
|
|
149
|
+
if (error)
|
|
150
|
+
reject(error);
|
|
151
|
+
else
|
|
152
|
+
resolve(data);
|
|
153
|
+
})
|
|
154
|
+
);
|
|
127
155
|
expect(transformedCode).toContain(
|
|
128
156
|
`<>
|
|
129
157
|
<div>Hello, world</div>
|
|
@@ -136,7 +164,14 @@ describe("replaceJSXTextInFile", () => {
|
|
|
136
164
|
const searchString = "world";
|
|
137
165
|
const replaceWith = "some-id";
|
|
138
166
|
yield (0, import_replace.replaceJSXTextInFile)(tempFile, { searchString, replaceWith }, {});
|
|
139
|
-
const transformedCode = yield
|
|
167
|
+
const transformedCode = yield new Promise(
|
|
168
|
+
(resolve, reject) => import_fs.default.readFile(tempFile, "utf-8", (error, data) => {
|
|
169
|
+
if (error)
|
|
170
|
+
reject(error);
|
|
171
|
+
else
|
|
172
|
+
resolve(data);
|
|
173
|
+
})
|
|
174
|
+
);
|
|
140
175
|
expect(transformedCode).toContain(
|
|
141
176
|
`<div>HeLLo, <DittoComponent componentId="${replaceWith}" /></div>`
|
|
142
177
|
);
|
|
@@ -146,10 +181,17 @@ describe("replaceJSXTextInFile", () => {
|
|
|
146
181
|
const searchString = "foobar";
|
|
147
182
|
const replaceWith = "some-id";
|
|
148
183
|
yield (0, import_replace.replaceJSXTextInFile)(tempFile, { searchString, replaceWith }, {});
|
|
149
|
-
const transformedCode = yield
|
|
184
|
+
const transformedCode = yield new Promise(
|
|
185
|
+
(resolve, reject) => import_fs.default.readFile(tempFile, "utf-8", (error, data) => {
|
|
186
|
+
if (error)
|
|
187
|
+
reject(error);
|
|
188
|
+
else
|
|
189
|
+
resolve(data);
|
|
190
|
+
})
|
|
191
|
+
);
|
|
150
192
|
expect(transformedCode).toContain("<div>Hello, world!</div>");
|
|
151
193
|
}));
|
|
152
194
|
});
|
|
153
195
|
//# sourceMappingURL=replace.test.js.map
|
|
154
196
|
|
|
155
|
-
//# debugId=
|
|
197
|
+
//# debugId=8d2eb72b-d2d6-5847-b480-cd39f4da1f7e
|
package/bin/replace.test.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../lib/replace.test.ts"],"sourcesContent":["import fs from \"fs
|
|
1
|
+
{"version":3,"sources":["../lib/replace.test.ts"],"sourcesContent":["import fs from \"fs\";\nimport { parseOptions, replaceJSXTextInFile } from \"./replace\"; // Assuming the function is exported in a separate file\n\njest.mock(\"fs\");\n\n// Helper function to create a temporary file\nasync function createTempJSXFile(content: string): Promise<string> {\n const tempFile = \"/tempFile.jsx\";\n await new Promise((resolve, reject) => {\n try {\n fs.writeFile(tempFile, content, resolve);\n } catch (e) {\n reject(e);\n }\n });\n return tempFile;\n}\n\n// Helper function to delete the temporary file\nasync function deleteTempFile(filePath: string): Promise<void> {\n await new Promise((resolve, reject) => {\n try {\n fs.unlink(filePath, resolve);\n } catch (e) {\n reject(e);\n }\n });\n}\n\ndescribe(\"parseOptions\", () => {\n test(\"should pass with valid input\", async () => {\n const tempFile = await createTempJSXFile(\"<div>Hello, world!</div>\");\n expect(() =>\n parseOptions([tempFile, \"secondString\", \"thirdString\"])\n ).not.toThrow();\n\n const result = parseOptions([tempFile, \"secondString\", \"thirdString\"]);\n expect(result).toEqual({\n filePath: tempFile,\n searchString: \"secondString\",\n replaceWith: \"thirdString\",\n });\n\n deleteTempFile(tempFile);\n });\n\n test(\"should throw error when options array does not have exactly three strings\", () => {\n expect(() => parseOptions([\"oneString\"])).toThrow(\n \"The options array must contain <file path> <search string> <replace with>.\"\n );\n expect(() => parseOptions([\"one\", \"two\"])).toThrow(\n \"The options array must contain <file path> <search string> <replace with>.\"\n );\n expect(() => parseOptions([\"one\", \"two\", \"three\", \"four\"])).toThrow(\n \"The options array must contain <file path> <search string> <replace with>.\"\n );\n });\n\n test(\"should throw error when the first string is not a valid file path\", () => {\n const invalidFilePath = \"/path/to/invalid/file.txt\";\n expect(() =>\n parseOptions([invalidFilePath, \"secondString\", \"thirdString\"])\n ).toThrow(`${invalidFilePath} is not a valid file path.`);\n });\n\n test(\"should throw error when the first string is a directory\", () => {\n const directoryPath = \".\";\n expect(() =>\n parseOptions([directoryPath, \"secondString\", \"thirdString\"])\n ).toThrow(`${directoryPath} is not a valid file path.`);\n });\n});\n\ndescribe(\"replaceJSXTextInFile\", () => {\n afterEach(async () => {\n await deleteTempFile(\"/tempFile.jsx\");\n });\n\n test(\"should replace JSX text with a DittoComponent\", async () => {\n const tempFile = await createTempJSXFile(\"<div>Hello, world</div>\");\n const searchString = \"world\";\n const replaceWith = \"some-id\";\n\n await replaceJSXTextInFile(tempFile, { searchString, replaceWith }, {});\n\n const transformedCode = await new Promise((resolve, reject) => {\n fs.readFile(tempFile, \"utf-8\", (error, data) => {\n if (error) {\n reject(error);\n } else {\n resolve(data);\n }\n });\n });\n expect(transformedCode).toContain(\n `<div>Hello, <DittoComponent componentId=\"${replaceWith}\" /></div>`\n );\n });\n\n test(\"should replace JSX text with a DittoComponent with a flag\", async () => {\n const tempFile = await createTempJSXFile(\n `<>\\n<div>Hello, world</div>\\n<div>Hello, world</div>\\n</>`\n );\n const searchString = \"world\";\n const replaceWith = \"some-id\";\n\n await replaceJSXTextInFile(\n tempFile,\n { searchString, replaceWith },\n { lineNumbers: [3] }\n );\n\n const transformedCode = await new Promise((resolve, reject) =>\n fs.readFile(tempFile, \"utf-8\", (error, data) => {\n if (error) reject(error);\n else resolve(data);\n })\n );\n expect(transformedCode).toContain(\n `<>\\n <div>Hello, world</div>\\n <div>Hello, <DittoComponent componentId=\\\"some-id\\\" /></div>\\n</>;`\n );\n });\n\n test(\"should handle case-insensitive search\", async () => {\n const tempFile = await createTempJSXFile(\"<div>HeLLo, WoRlD</div>\");\n const searchString = \"world\";\n const replaceWith = \"some-id\";\n\n await replaceJSXTextInFile(tempFile, { searchString, replaceWith }, {});\n\n const transformedCode = await new Promise((resolve, reject) =>\n fs.readFile(tempFile, \"utf-8\", (error, data) => {\n if (error) reject(error);\n else resolve(data);\n })\n );\n expect(transformedCode).toContain(\n `<div>HeLLo, <DittoComponent componentId=\"${replaceWith}\" /></div>`\n );\n });\n\n test(\"should not replace JSX text if searchString is not found\", async () => {\n const tempFile = await createTempJSXFile(\"<div>Hello, world!</div>\");\n const searchString = \"foobar\";\n const replaceWith = \"some-id\";\n\n await replaceJSXTextInFile(tempFile, { searchString, replaceWith }, {});\n\n const transformedCode = await new Promise((resolve, reject) =>\n fs.readFile(tempFile, \"utf-8\", (error, data) => {\n if (error) reject(error);\n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7e"}
|
package/bin/types.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="31cef992-b35d-58a1-b36c-4df7755fb649")}catch(e){}}();
|
|
3
3
|
|
|
4
4
|
var __defProp = Object.defineProperty;
|
|
5
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -18,4 +18,4 @@ var types_exports = {};
|
|
|
18
18
|
module.exports = __toCommonJS(types_exports);
|
|
19
19
|
//# sourceMappingURL=types.js.map
|
|
20
20
|
|
|
21
|
-
//# debugId=
|
|
21
|
+
//# debugId=31cef992-b35d-58a1-b36c-4df7755fb649
|
package/bin/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../lib/types.ts"],"sourcesContent":["export interface Project {\n name: string;\n id: string;\n url?: string;\n fileName?: string;\n status?: string;\n exclude_components?: boolean;\n}\n\nexport type ComponentSource = ComponentFolder & {\n type: \"components\";\n fileName: string;\n variant: string;\n};\n\nexport type Source = (Project & { type?: undefined }) | ComponentSource;\n\nexport interface ComponentFolder {\n id: string;\n name: string;\n status?: string;\n}\n\nexport type SupportedFormat =\n | \"flat\"\n | \"nested\"\n | \"structured\"\n | \"android\"\n | \"ios-strings\"\n | \"ios-stringsdict\"\n | \"icu\";\n\nexport type SupportedExtension = \".json\" | \".xml\" | \".strings\" | \".stringsdict\";\n\ntype ComponentsSourceBool = boolean;\ntype ComponentsSourceConfig = {\n root?: boolean | { status: string };\n folders?: ComponentFolder[];\n};\ntype ComponentsSource = ComponentsSourceBool | ComponentsSourceConfig;\n\nexport interface ConfigYAML {\n sources?: {\n components?: ComponentsSource;\n projects?: Project[];\n };\n format?: SupportedFormat;\n status?: string;\n variants?: boolean;\n richText?: boolean;\n\n // TODO: might want to rename this at some point\n iosLocales?: Record<string, string>[];\n\n // these are legacy fields - if they exist, we should output\n // a deprecation error, and suggest that they nest them under\n // a top-level `sources` property\n components?: boolean;\n projects?: Project[];\n}\n\nexport interface SourceInformation {\n hasSourceData: boolean;\n hasTopLevelProjectsField: boolean;\n hasTopLevelComponentsField: boolean;\n hasComponentLibraryInProjects: boolean;\n validProjects: Project[];\n shouldFetchComponentLibrary: boolean;\n variants: boolean;\n format: string | string[] | undefined;\n status: string | undefined;\n richText: boolean | undefined;\n componentRoot: boolean | { status: string } | undefined;\n componentFolders: ComponentFolder[] | undefined;\n localeByVariantApiId: Record<string, string> | undefined;\n}\n\nexport type Token = string | undefined;\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA","debug_id":"
|
|
1
|
+
{"version":3,"sources":["../lib/types.ts"],"sourcesContent":["export interface Project {\n name: string;\n id: string;\n url?: string;\n fileName?: string;\n status?: string;\n exclude_components?: boolean;\n}\n\nexport type ComponentSource = ComponentFolder & {\n type: \"components\";\n fileName: string;\n variant: string;\n};\n\nexport type Source = (Project & { type?: undefined }) | ComponentSource;\n\nexport interface ComponentFolder {\n id: string;\n name: string;\n status?: string;\n}\n\nexport type SupportedFormat =\n | \"flat\"\n | \"nested\"\n | \"structured\"\n | \"android\"\n | \"ios-strings\"\n | \"ios-stringsdict\"\n | \"icu\";\n\nexport type SupportedExtension = \".json\" | \".xml\" | \".strings\" | \".stringsdict\";\n\ntype ComponentsSourceBool = boolean;\ntype ComponentsSourceConfig = {\n root?: boolean | { status: string };\n folders?: ComponentFolder[];\n};\ntype ComponentsSource = ComponentsSourceBool | ComponentsSourceConfig;\n\nexport interface ConfigYAML {\n sources?: {\n components?: ComponentsSource;\n projects?: Project[];\n };\n format?: SupportedFormat;\n status?: string;\n variants?: boolean;\n richText?: boolean;\n\n // TODO: might want to rename this at some point\n iosLocales?: Record<string, string>[];\n\n // prevents the generation of index.js and index.d.ts files\n // when working with JSON formats\n disableJsDriver?: boolean;\n\n // these are legacy fields - if they exist, we should output\n // a deprecation error, and suggest that they nest them under\n // a top-level `sources` property\n components?: boolean;\n projects?: Project[];\n}\n\nexport interface SourceInformation {\n hasSourceData: boolean;\n hasTopLevelProjectsField: boolean;\n hasTopLevelComponentsField: boolean;\n hasComponentLibraryInProjects: boolean;\n validProjects: Project[];\n shouldFetchComponentLibrary: boolean;\n variants: boolean;\n format: string | string[] | undefined;\n status: string | undefined;\n richText: boolean | undefined;\n componentRoot: boolean | { status: string } | undefined;\n componentFolders: ComponentFolder[] | undefined;\n localeByVariantApiId: Record<string, string> | undefined;\n disableJsDriver?: boolean;\n}\n\nexport type Token = string | undefined;\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA","debug_id":"31cef992-b35d-58a1-b36c-4df7755fb649"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="6334441d-042a-5df3-9f37-7bd9fd9adae4")}catch(e){}}();
|
|
3
3
|
|
|
4
4
|
var __create = Object.create;
|
|
5
5
|
var __defProp = Object.defineProperty;
|
|
@@ -35,15 +35,14 @@ __export(determineModuleType_exports, {
|
|
|
35
35
|
module.exports = __toCommonJS(determineModuleType_exports);
|
|
36
36
|
var fs = __toESM(require("fs"));
|
|
37
37
|
var path = __toESM(require("path"));
|
|
38
|
-
function determineModuleType() {
|
|
39
|
-
const value = getRawTypeFromPackageJson();
|
|
38
|
+
function determineModuleType(currentDir = process.cwd()) {
|
|
39
|
+
const value = getRawTypeFromPackageJson(currentDir);
|
|
40
40
|
return getTypeOrDefault(value);
|
|
41
41
|
}
|
|
42
|
-
function getRawTypeFromPackageJson() {
|
|
42
|
+
function getRawTypeFromPackageJson(currentDir) {
|
|
43
43
|
if (process.env.DITTO_MODULE_TYPE) {
|
|
44
44
|
return process.env.DITTO_MODULE_TYPE;
|
|
45
45
|
}
|
|
46
|
-
let currentDir = process.cwd();
|
|
47
46
|
while (currentDir) {
|
|
48
47
|
const packageJsonPath = path.join(currentDir, "package.json");
|
|
49
48
|
if (fs.existsSync(packageJsonPath)) {
|
|
@@ -58,7 +57,7 @@ function getRawTypeFromPackageJson() {
|
|
|
58
57
|
return null;
|
|
59
58
|
}
|
|
60
59
|
if (currentDir === "/") {
|
|
61
|
-
|
|
60
|
+
break;
|
|
62
61
|
}
|
|
63
62
|
currentDir = path.dirname(currentDir);
|
|
64
63
|
}
|
|
@@ -77,4 +76,4 @@ function getTypeOrDefault(value) {
|
|
|
77
76
|
});
|
|
78
77
|
//# sourceMappingURL=determineModuleType.js.map
|
|
79
78
|
|
|
80
|
-
//# debugId=
|
|
79
|
+
//# debugId=6334441d-042a-5df3-9f37-7bd9fd9adae4
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../lib/utils/determineModuleType.ts"],"sourcesContent":["import * as fs from \"fs\";\nimport * as path from \"path\";\n\nexport type ModuleType = \"commonjs\" | \"module\";\n\n/**\n * Looks for a `package.json` file starting in the current working directory and traversing upwards\n * until it finds one or reaches root.\n * @returns \"commonjs\" or \"module\", defaulting to \"module\" if no `package.json` is found or if the found\n * file does not include a `type` property.\n */\nexport function determineModuleType() {\n const value = getRawTypeFromPackageJson();\n return getTypeOrDefault(value);\n}\n\nfunction getRawTypeFromPackageJson() {\n if (process.env.DITTO_MODULE_TYPE) {\n return process.env.DITTO_MODULE_TYPE;\n }\n\n
|
|
1
|
+
{"version":3,"sources":["../../lib/utils/determineModuleType.ts"],"sourcesContent":["import * as fs from \"fs\";\nimport * as path from \"path\";\n\nexport type ModuleType = \"commonjs\" | \"module\";\n\n/**\n * Looks for a `package.json` file starting in the current working directory and traversing upwards\n * until it finds one or reaches root.\n * @returns \"commonjs\" or \"module\", defaulting to \"module\" if no `package.json` is found or if the found\n * file does not include a `type` property.\n */\nexport function determineModuleType(currentDir: string | null = process.cwd()) {\n const value = getRawTypeFromPackageJson(currentDir);\n return getTypeOrDefault(value);\n}\n\nfunction getRawTypeFromPackageJson(currentDir: string | null) {\n if (process.env.DITTO_MODULE_TYPE) {\n return process.env.DITTO_MODULE_TYPE;\n }\n\n while (currentDir) {\n const packageJsonPath = path.join(currentDir, \"package.json\");\n if (fs.existsSync(packageJsonPath)) {\n const packageJsonContents = fs.readFileSync(packageJsonPath, \"utf8\");\n try {\n const packageData: { type?: string } = JSON.parse(packageJsonContents);\n if (packageData?.type) {\n return packageData.type;\n }\n } catch {}\n\n return null;\n }\n\n if (currentDir === \"/\") {\n break;\n }\n\n // Move up a directory and continue the search\n currentDir = path.dirname(currentDir);\n }\n\n // No package.json\n return null;\n}\n\nfunction getTypeOrDefault(value: string | null): ModuleType {\n const valueLower = value?.toLowerCase() || \"\";\n if (valueLower === \"commonjs\" || valueLower === \"module\") {\n return valueLower;\n }\n\n return \"commonjs\";\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,SAAoB;AACpB,WAAsB;AAUf,SAAS,oBAAoB,aAA4B,QAAQ,IAAI,GAAG;AAC7E,QAAM,QAAQ,0BAA0B,UAAU;AAClD,SAAO,iBAAiB,KAAK;AAC/B;AAEA,SAAS,0BAA0B,YAA2B;AAC5D,MAAI,QAAQ,IAAI,mBAAmB;AACjC,WAAO,QAAQ,IAAI;AAAA,EACrB;AAEA,SAAO,YAAY;AACjB,UAAM,kBAAkB,KAAK,KAAK,YAAY,cAAc;AAC5D,QAAI,GAAG,WAAW,eAAe,GAAG;AAClC,YAAM,sBAAsB,GAAG,aAAa,iBAAiB,MAAM;AACnE,UAAI;AACF,cAAM,cAAiC,KAAK,MAAM,mBAAmB;AACrE,YAAI,2CAAa,MAAM;AACrB,iBAAO,YAAY;AAAA,QACrB;AAAA,MACF,SAAQ;AAAA,MAAC;AAET,aAAO;AAAA,IACT;AAEA,QAAI,eAAe,KAAK;AACtB;AAAA,IACF;AAGA,iBAAa,KAAK,QAAQ,UAAU;AAAA,EACtC;AAGA,SAAO;AACT;AAEA,SAAS,iBAAiB,OAAkC;AAC1D,QAAM,cAAa,+BAAO,kBAAiB;AAC3C,MAAI,eAAe,cAAc,eAAe,UAAU;AACxD,WAAO;AAAA,EACT;AAEA,SAAO;AACT","debug_id":"6334441d-042a-5df3-9f37-7bd9fd9adae4"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="31410f07-eaa0-59b5-a32b-1c709affaf87")}catch(e){}}();
|
|
3
|
+
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
8
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
+
var __spreadValues = (a, b) => {
|
|
10
|
+
for (var prop in b || (b = {}))
|
|
11
|
+
if (__hasOwnProp.call(b, prop))
|
|
12
|
+
__defNormalProp(a, prop, b[prop]);
|
|
13
|
+
if (__getOwnPropSymbols)
|
|
14
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
15
|
+
if (__propIsEnum.call(b, prop))
|
|
16
|
+
__defNormalProp(a, prop, b[prop]);
|
|
17
|
+
}
|
|
18
|
+
return a;
|
|
19
|
+
};
|
|
20
|
+
var import_determineModuleType = require("./determineModuleType");
|
|
21
|
+
var import_memfs = require("memfs");
|
|
22
|
+
const defaultEnv = process.env;
|
|
23
|
+
jest.mock("fs");
|
|
24
|
+
beforeEach(() => {
|
|
25
|
+
import_memfs.vol.reset();
|
|
26
|
+
process.env = __spreadValues({}, defaultEnv);
|
|
27
|
+
});
|
|
28
|
+
test("'commonjs' if no package.json found", () => {
|
|
29
|
+
expect((0, import_determineModuleType.determineModuleType)()).toBe("commonjs");
|
|
30
|
+
});
|
|
31
|
+
test("'commonjs' if package.json found but no `type` property", () => {
|
|
32
|
+
import_memfs.vol.fromJSON({ "package.json": JSON.stringify({}) }, process.cwd());
|
|
33
|
+
expect((0, import_determineModuleType.determineModuleType)()).toBe("commonjs");
|
|
34
|
+
});
|
|
35
|
+
test("'commonjs' if package.json found and `type` property is 'commonjs'", () => {
|
|
36
|
+
import_memfs.vol.fromJSON({ "package.json": JSON.stringify({ type: "commonjs" }) });
|
|
37
|
+
expect((0, import_determineModuleType.determineModuleType)()).toBe("commonjs");
|
|
38
|
+
});
|
|
39
|
+
test("'commonjs' if package.json found and `type` property is invalid", () => {
|
|
40
|
+
import_memfs.vol.fromJSON({ "package.json": JSON.stringify({ type: "invalid-type" }) });
|
|
41
|
+
expect((0, import_determineModuleType.determineModuleType)()).toBe("commonjs");
|
|
42
|
+
});
|
|
43
|
+
test("'module' if package.json found and `type` property is 'module'", () => {
|
|
44
|
+
import_memfs.vol.fromJSON({ "package.json": JSON.stringify({ type: "module" }) });
|
|
45
|
+
expect((0, import_determineModuleType.determineModuleType)()).toBe("module");
|
|
46
|
+
});
|
|
47
|
+
test("finds package.json in parent directories", () => {
|
|
48
|
+
import_memfs.vol.fromJSON({
|
|
49
|
+
"/some/nested/dir/test.txt": "",
|
|
50
|
+
"/package.json": JSON.stringify({ type: "module" })
|
|
51
|
+
});
|
|
52
|
+
expect((0, import_determineModuleType.determineModuleType)("/some/nested/dir")).toBe("module");
|
|
53
|
+
});
|
|
54
|
+
test("supports explicit specification of module type via environment variable", () => {
|
|
55
|
+
process.env.DITTO_MODULE_TYPE = "module";
|
|
56
|
+
expect((0, import_determineModuleType.determineModuleType)()).toBe("module");
|
|
57
|
+
});
|
|
58
|
+
//# sourceMappingURL=determineModuleType.test.js.map
|
|
59
|
+
|
|
60
|
+
//# debugId=31410f07-eaa0-59b5-a32b-1c709affaf87
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../lib/utils/determineModuleType.test.ts"],"sourcesContent":["import { determineModuleType } from \"./determineModuleType\";\nimport { vol } from \"memfs\";\n\nconst defaultEnv = process.env;\n\njest.mock(\"fs\");\n\nbeforeEach(() => {\n vol.reset();\n process.env = { ...defaultEnv };\n});\n\ntest(\"'commonjs' if no package.json found\", () => {\n expect(determineModuleType()).toBe(\"commonjs\");\n});\n\ntest(\"'commonjs' if package.json found but no `type` property\", () => {\n vol.fromJSON({ \"package.json\": JSON.stringify({}) }, process.cwd());\n expect(determineModuleType()).toBe(\"commonjs\");\n});\n\ntest(\"'commonjs' if package.json found and `type` property is 'commonjs'\", () => {\n vol.fromJSON({ \"package.json\": JSON.stringify({ type: \"commonjs\" }) });\n expect(determineModuleType()).toBe(\"commonjs\");\n});\n\ntest(\"'commonjs' if package.json found and `type` property is invalid\", () => {\n vol.fromJSON({ \"package.json\": JSON.stringify({ type: \"invalid-type\" }) });\n expect(determineModuleType()).toBe(\"commonjs\");\n});\n\ntest(\"'module' if package.json found and `type` property is 'module'\", () => {\n vol.fromJSON({ \"package.json\": JSON.stringify({ type: \"module\" }) });\n expect(determineModuleType()).toBe(\"module\");\n});\n\ntest(\"finds package.json in parent directories\", () => {\n vol.fromJSON({\n \"/some/nested/dir/test.txt\": \"\",\n \"/package.json\": JSON.stringify({ type: \"module\" }),\n });\n expect(determineModuleType(\"/some/nested/dir\")).toBe(\"module\");\n});\n\ntest(\"supports explicit specification of module type via environment variable\", () => {\n process.env.DITTO_MODULE_TYPE = \"module\";\n expect(determineModuleType()).toBe(\"module\");\n});\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AAAA,iCAAoC;AACpC,mBAAoB;AAEpB,MAAM,aAAa,QAAQ;AAE3B,KAAK,KAAK,IAAI;AAEd,WAAW,MAAM;AACf,mBAAI,MAAM;AACV,UAAQ,MAAM,mBAAK;AACrB,CAAC;AAED,KAAK,uCAAuC,MAAM;AAChD,aAAO,gDAAoB,CAAC,EAAE,KAAK,UAAU;AAC/C,CAAC;AAED,KAAK,2DAA2D,MAAM;AACpE,mBAAI,SAAS,EAAE,gBAAgB,KAAK,UAAU,CAAC,CAAC,EAAE,GAAG,QAAQ,IAAI,CAAC;AAClE,aAAO,gDAAoB,CAAC,EAAE,KAAK,UAAU;AAC/C,CAAC;AAED,KAAK,sEAAsE,MAAM;AAC/E,mBAAI,SAAS,EAAE,gBAAgB,KAAK,UAAU,EAAE,MAAM,WAAW,CAAC,EAAE,CAAC;AACrE,aAAO,gDAAoB,CAAC,EAAE,KAAK,UAAU;AAC/C,CAAC;AAED,KAAK,mEAAmE,MAAM;AAC5E,mBAAI,SAAS,EAAE,gBAAgB,KAAK,UAAU,EAAE,MAAM,eAAe,CAAC,EAAE,CAAC;AACzE,aAAO,gDAAoB,CAAC,EAAE,KAAK,UAAU;AAC/C,CAAC;AAED,KAAK,kEAAkE,MAAM;AAC3E,mBAAI,SAAS,EAAE,gBAAgB,KAAK,UAAU,EAAE,MAAM,SAAS,CAAC,EAAE,CAAC;AACnE,aAAO,gDAAoB,CAAC,EAAE,KAAK,QAAQ;AAC7C,CAAC;AAED,KAAK,4CAA4C,MAAM;AACrD,mBAAI,SAAS;AAAA,IACX,6BAA6B;AAAA,IAC7B,iBAAiB,KAAK,UAAU,EAAE,MAAM,SAAS,CAAC;AAAA,EACpD,CAAC;AACD,aAAO,gDAAoB,kBAAkB,CAAC,EAAE,KAAK,QAAQ;AAC/D,CAAC;AAED,KAAK,2EAA2E,MAAM;AACpF,UAAQ,IAAI,oBAAoB;AAChC,aAAO,gDAAoB,CAAC,EAAE,KAAK,QAAQ;AAC7C,CAAC","debug_id":"31410f07-eaa0-59b5-a32b-1c709affaf87"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="ca926dda-44e3-512a-b95e-05b445329a2e")}catch(e){}}();
|
|
3
3
|
|
|
4
4
|
var __create = Object.create;
|
|
5
5
|
var __defProp = Object.defineProperty;
|
|
@@ -35,7 +35,7 @@ __export(getSelectedProjects_exports, {
|
|
|
35
35
|
});
|
|
36
36
|
module.exports = __toCommonJS(getSelectedProjects_exports);
|
|
37
37
|
var import_js_yaml = __toESM(require("js-yaml"));
|
|
38
|
-
var import_consts = require("../consts");
|
|
38
|
+
var import_consts = __toESM(require("../consts"));
|
|
39
39
|
var import_config = __toESM(require("../config"));
|
|
40
40
|
function jsonIsConfigYAML(json) {
|
|
41
41
|
return typeof json === "object";
|
|
@@ -55,8 +55,8 @@ function yamlToJson(_yaml) {
|
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
|
-
const getSelectedProjects = (configFile = import_consts.PROJECT_CONFIG_FILE) => import_config.default.parseSourceInformation(configFile).validProjects;
|
|
59
|
-
const getIsUsingComponents = (configFile = import_consts.PROJECT_CONFIG_FILE) => import_config.default.parseSourceInformation(configFile).shouldFetchComponentLibrary;
|
|
58
|
+
const getSelectedProjects = (configFile = import_consts.default.PROJECT_CONFIG_FILE) => import_config.default.parseSourceInformation(configFile).validProjects;
|
|
59
|
+
const getIsUsingComponents = (configFile = import_consts.default.PROJECT_CONFIG_FILE) => import_config.default.parseSourceInformation(configFile).shouldFetchComponentLibrary;
|
|
60
60
|
// Annotate the CommonJS export names for ESM import in node:
|
|
61
61
|
0 && (module.exports = {
|
|
62
62
|
getIsUsingComponents,
|
|
@@ -64,4 +64,4 @@ const getIsUsingComponents = (configFile = import_consts.PROJECT_CONFIG_FILE) =>
|
|
|
64
64
|
});
|
|
65
65
|
//# sourceMappingURL=getSelectedProjects.js.map
|
|
66
66
|
|
|
67
|
-
//# debugId=
|
|
67
|
+
//# debugId=ca926dda-44e3-512a-b95e-05b445329a2e
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../lib/utils/getSelectedProjects.ts"],"sourcesContent":["import fs from \"fs\";\nimport yaml, { YAMLException } from \"js-yaml\";\n\nimport
|
|
1
|
+
{"version":3,"sources":["../../lib/utils/getSelectedProjects.ts"],"sourcesContent":["import fs from \"fs\";\nimport yaml, { YAMLException } from \"js-yaml\";\n\nimport consts from \"../consts\";\nimport { ConfigYAML, Project } from \"../types\";\nimport Config, { DEFAULT_CONFIG_JSON } from \"../config\";\n\nfunction jsonIsConfigYAML(json: unknown): json is ConfigYAML {\n return typeof json === \"object\";\n}\n\nfunction yamlToJson(_yaml: string): ConfigYAML | null {\n try {\n let configYaml = yaml.load(_yaml);\n if (!jsonIsConfigYAML(configYaml)) {\n return {};\n }\n return configYaml;\n } catch (e) {\n if (e instanceof YAMLException) {\n return null;\n } else {\n throw e;\n }\n }\n}\n\n/**\n * Returns an array containing all valid projects ({ id, name })\n * currently contained in the project config file.\n */\nexport const getSelectedProjects = (configFile = consts.PROJECT_CONFIG_FILE) =>\n Config.parseSourceInformation(configFile).validProjects;\n\nexport const getIsUsingComponents = (configFile = consts.PROJECT_CONFIG_FILE) =>\n Config.parseSourceInformation(configFile).shouldFetchComponentLibrary;\n"],"names":["yaml","consts","Config"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,qBAAoC;AAEpC,oBAAmB;AAEnB,oBAA4C;AAE5C,SAAS,iBAAiB,MAAmC;AAC3D,SAAO,OAAO,SAAS;AACzB;AAEA,SAAS,WAAW,OAAkC;AACpD,MAAI;AACF,QAAI,aAAa,eAAAA,QAAK,KAAK,KAAK;AAChC,QAAI,CAAC,iBAAiB,UAAU,GAAG;AACjC,aAAO,CAAC;AAAA,IACV;AACA,WAAO;AAAA,EACT,SAAS,GAAG;AACV,QAAI,aAAa,8BAAe;AAC9B,aAAO;AAAA,IACT,OAAO;AACL,YAAM;AAAA,IACR;AAAA,EACF;AACF;AAMO,MAAM,sBAAsB,CAAC,aAAa,cAAAC,QAAO,wBACtD,cAAAC,QAAO,uBAAuB,UAAU,EAAE;AAErC,MAAM,uBAAuB,CAAC,aAAa,cAAAD,QAAO,wBACvD,cAAAC,QAAO,uBAAuB,UAAU,EAAE","debug_id":"ca926dda-44e3-512a-b95e-05b445329a2e"}
|
package/bin/utils/quit.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="79239749-0258-5746-9b26-d5a38d1e3f33")}catch(e){}}();
|
|
3
3
|
|
|
4
4
|
var __defProp = Object.defineProperty;
|
|
5
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -28,7 +28,7 @@ function quit(message, exitCode = 2) {
|
|
|
28
28
|
console.log(`
|
|
29
29
|
${message}
|
|
30
30
|
`);
|
|
31
|
-
process.exitCode
|
|
31
|
+
process.exit(exitCode);
|
|
32
32
|
}
|
|
33
33
|
// Annotate the CommonJS export names for ESM import in node:
|
|
34
34
|
0 && (module.exports = {
|
|
@@ -36,4 +36,4 @@ ${message}
|
|
|
36
36
|
});
|
|
37
37
|
//# sourceMappingURL=quit.js.map
|
|
38
38
|
|
|
39
|
-
//# debugId=
|
|
39
|
+
//# debugId=79239749-0258-5746-9b26-d5a38d1e3f33
|
package/bin/utils/quit.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../lib/utils/quit.ts"],"sourcesContent":["export function quit(message: string | null, exitCode = 2) {\n if (message) console.log(`\\n${message}\\n`);\n process.exitCode
|
|
1
|
+
{"version":3,"sources":["../../lib/utils/quit.ts"],"sourcesContent":["export function quit(message: string | null, exitCode = 2) {\n if (message) console.log(`\\n${message}\\n`);\n process.exit(exitCode);\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,SAAS,KAAK,SAAwB,WAAW,GAAG;AACzD,MAAI;AAAS,YAAQ,IAAI;AAAA,EAAK,OAAO;AAAA,CAAI;AACzC,UAAQ,KAAK,QAAQ;AACvB","debug_id":"79239749-0258-5746-9b26-d5a38d1e3f33"}
|
package/jest.config.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Config } from "jest";
|
|
2
|
+
|
|
3
|
+
const config: Config = {
|
|
4
|
+
transformIgnorePatterns: [],
|
|
5
|
+
maxWorkers: 1,
|
|
6
|
+
verbose: true,
|
|
7
|
+
testPathIgnorePatterns: [
|
|
8
|
+
"<rootDir>/node_modules/",
|
|
9
|
+
"<rootDir>/dist/",
|
|
10
|
+
"<rootDir>/bin/",
|
|
11
|
+
],
|
|
12
|
+
watchPathIgnorePatterns: ["<rootDir>/.testing/", "<rootDir>/testing/"],
|
|
13
|
+
collectCoverageFrom: ["lib/**/*.{js,jsx,ts,tsx}"],
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export default config;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import { jest } from "@jest/globals";
|
|
3
|
+
|
|
4
|
+
jest.mock("axios");
|
|
5
|
+
|
|
6
|
+
// by returning the mocked module directly, we can mock responses in tests
|
|
7
|
+
// like `axios.get.mockResolvedValue()`; otherwise, we'd be unable to mock
|
|
8
|
+
// responses because `createApiClient` would be returning an axios instance
|
|
9
|
+
// unaffected by mocks applied to the `axios` module itself.
|
|
10
|
+
export function createApiClient(_token?: string) {
|
|
11
|
+
return axios;
|
|
12
|
+
}
|
package/lib/config.test.ts
CHANGED
|
@@ -5,7 +5,9 @@ import tempy from "tempy";
|
|
|
5
5
|
import yaml from "js-yaml";
|
|
6
6
|
import config from "./config";
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
jest.mock("fs");
|
|
9
|
+
|
|
10
|
+
const fakeHomedir = fs.mkdtempSync("/config-testing");
|
|
9
11
|
|
|
10
12
|
describe("Config File", () => {
|
|
11
13
|
const expectedConfigDir = path.join(fakeHomedir, ".config");
|
package/lib/config.ts
CHANGED
|
@@ -6,7 +6,7 @@ import * as Sentry from "@sentry/node";
|
|
|
6
6
|
|
|
7
7
|
import consts from "./consts";
|
|
8
8
|
import { createSentryContext } from "./utils/createSentryContext";
|
|
9
|
-
import { Project, ConfigYAML, SourceInformation } from "./types";
|
|
9
|
+
import { Project, ConfigYAML, SourceInformation, Source } from "./types";
|
|
10
10
|
|
|
11
11
|
export const DEFAULT_CONFIG_JSON: ConfigYAML = {
|
|
12
12
|
sources: {
|
|
@@ -198,6 +198,7 @@ function parseSourceInformation(file?: string): SourceInformation {
|
|
|
198
198
|
iosLocales,
|
|
199
199
|
projects: projectsRoot,
|
|
200
200
|
components: componentsRoot,
|
|
201
|
+
disableJsDriver,
|
|
201
202
|
} = readProjectConfigData(file);
|
|
202
203
|
|
|
203
204
|
const projects = sources?.projects || [];
|
|
@@ -239,7 +240,7 @@ function parseSourceInformation(file?: string): SourceInformation {
|
|
|
239
240
|
*/
|
|
240
241
|
const hasSourceData = !!validProjects.length || shouldFetchComponentLibrary;
|
|
241
242
|
|
|
242
|
-
const result = {
|
|
243
|
+
const result: SourceInformation = {
|
|
243
244
|
hasSourceData,
|
|
244
245
|
validProjects,
|
|
245
246
|
shouldFetchComponentLibrary,
|
|
@@ -255,6 +256,7 @@ function parseSourceInformation(file?: string): SourceInformation {
|
|
|
255
256
|
localeByVariantApiId: iosLocales
|
|
256
257
|
? iosLocales.reduce((acc, e) => ({ ...acc, ...e }), {} as any)
|
|
257
258
|
: undefined,
|
|
259
|
+
disableJsDriver,
|
|
258
260
|
};
|
|
259
261
|
|
|
260
262
|
Sentry.setContext("config", createSentryContext(result));
|
package/lib/consts.ts
CHANGED
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
import { homedir } from "os";
|
|
2
2
|
import path from "path";
|
|
3
3
|
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
)
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
TEXT_FILE
|
|
20
|
-
|
|
4
|
+
export default new (class {
|
|
5
|
+
get API_HOST() {
|
|
6
|
+
return process.env.DITTO_API_HOST || "https://api.dittowords.com";
|
|
7
|
+
}
|
|
8
|
+
get CONFIG_FILE() {
|
|
9
|
+
return (
|
|
10
|
+
process.env.DITTO_CONFIG_FILE || path.join(homedir(), ".config", "ditto")
|
|
11
|
+
);
|
|
12
|
+
}
|
|
13
|
+
get PROJECT_CONFIG_FILE() {
|
|
14
|
+
return path.normalize(path.join("ditto", "config.yml"));
|
|
15
|
+
}
|
|
16
|
+
get TEXT_DIR() {
|
|
17
|
+
return process.env.DITTO_TEXT_DIR || "ditto";
|
|
18
|
+
}
|
|
19
|
+
get TEXT_FILE() {
|
|
20
|
+
return path.normalize(path.join(this.TEXT_DIR, "text.json"));
|
|
21
|
+
}
|
|
22
|
+
})();
|
|
@@ -1,17 +1,31 @@
|
|
|
1
|
-
import fs from "fs
|
|
1
|
+
import fs from "fs";
|
|
2
2
|
import path from "path";
|
|
3
3
|
import { findComponentsInJSXFiles } from "./generate-suggestions";
|
|
4
4
|
|
|
5
|
+
jest.mock("fs");
|
|
6
|
+
|
|
5
7
|
describe("findTextInJSXFiles", () => {
|
|
6
8
|
async function createTempFile(filename: string, content: string) {
|
|
7
|
-
const filePath = path.join("
|
|
8
|
-
await
|
|
9
|
+
const filePath = path.join("/", filename);
|
|
10
|
+
await new Promise((resolve, reject) => {
|
|
11
|
+
try {
|
|
12
|
+
fs.writeFile(filePath, content, () => resolve(null));
|
|
13
|
+
} catch (e) {
|
|
14
|
+
reject(e);
|
|
15
|
+
}
|
|
16
|
+
});
|
|
9
17
|
return filePath;
|
|
10
18
|
}
|
|
11
19
|
|
|
12
20
|
async function deleteTempFile(filename: string) {
|
|
13
|
-
const filePath = path.join("
|
|
14
|
-
await
|
|
21
|
+
const filePath = path.join("/", filename);
|
|
22
|
+
await new Promise((resolve, reject) => {
|
|
23
|
+
try {
|
|
24
|
+
fs.unlink(filePath, resolve);
|
|
25
|
+
} catch (e) {
|
|
26
|
+
reject(e);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
15
29
|
}
|
|
16
30
|
|
|
17
31
|
it("should return an empty obj when no files are found", async () => {
|
|
@@ -74,7 +88,7 @@ describe("findTextInJSXFiles", () => {
|
|
|
74
88
|
};
|
|
75
89
|
|
|
76
90
|
const result = await findComponentsInJSXFiles({
|
|
77
|
-
directory: "
|
|
91
|
+
directory: "/",
|
|
78
92
|
components: {
|
|
79
93
|
"search-string": {
|
|
80
94
|
name: "Search String",
|
|
@@ -119,8 +133,7 @@ describe("findTextInJSXFiles", () => {
|
|
|
119
133
|
};
|
|
120
134
|
|
|
121
135
|
const result = await findComponentsInJSXFiles({
|
|
122
|
-
|
|
123
|
-
files: ["file1.jsx"],
|
|
136
|
+
files: ["/file1.jsx"],
|
|
124
137
|
components: {
|
|
125
138
|
"search-string": {
|
|
126
139
|
name: "Search String",
|
|
@@ -134,9 +147,8 @@ describe("findTextInJSXFiles", () => {
|
|
|
134
147
|
expect(result).toEqual(expectedResult);
|
|
135
148
|
|
|
136
149
|
try {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
files: ["file2.jsx"],
|
|
150
|
+
await findComponentsInJSXFiles({
|
|
151
|
+
files: ["/file2.jsx"],
|
|
140
152
|
components: {
|
|
141
153
|
"search-string": {
|
|
142
154
|
name: "Search String",
|