Skip to content

Commit d2db408

Browse files
authored
Merge branch 'main' into chore/[email protected]
2 parents f4463bd + 7d41a92 commit d2db408

File tree

6 files changed

+20
-53
lines changed

6 files changed

+20
-53
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212

1313
strategy:
1414
matrix:
15-
node-version: [18.x]
15+
node-version: [20.x]
1616

1717
steps:
1818
- name: Checkout
@@ -21,7 +21,7 @@ jobs:
2121
- name: Install Node.js
2222
uses: actions/setup-node@v3
2323
with:
24-
node-version: 18
24+
node-version: 20
2525
- run: npm install
2626
- name: Setup Chomp
2727
uses: guybedford/chomp-action@v1

src/__tests__/parser.test.ts

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,6 @@ jest.mock('@jspm/generator', () => ({
2121
parseUrlPkg: jest.fn(),
2222
}))
2323

24-
jest.mock("../utils", () => {
25-
const actual = jest.requireActual("../utils");
26-
return {
27-
__esModule: true,
28-
...actual,
29-
};
30-
});
31-
import * as utils from "../utils";
32-
3324
jest.mock('../config')
3425

3526
describe("parseNodeModuleCachePath", () => {
@@ -52,22 +43,4 @@ describe("parseNodeModuleCachePath", () => {
5243
const result = await parseNodeModuleCachePath("modulePath", cachePath);
5344
expect(result).toBe(cachePath);
5445
});
55-
56-
test("should make directories and write file if cachePath does not exist", async () => {
57-
jest.spyOn(fs, "existsSync").mockReturnValue(false);
58-
const ensureFileSyncSpy = jest.spyOn(utils, "ensureFileSync");
59-
await parseNodeModuleCachePath("modulePath", cachePath);
60-
expect(ensureFileSyncSpy).toBeCalled();
61-
});
62-
63-
test("should return empty string if there is an error", async () => {
64-
jest.spyOn(fs, "existsSync").mockReturnValue(false);
65-
await jest.spyOn(fs, "writeFileSync").mockImplementation(() => {
66-
throw new Error("error");
67-
});
68-
const errorSpy = await jest.spyOn(console, "error").mockImplementation(() => undefined);
69-
const result = await parseNodeModuleCachePath("modulePath", cachePath);
70-
expect(result).toBe("file:///path/to/cache");
71-
expect(errorSpy).toHaveBeenCalled();
72-
});
7346
});

src/__tests__/utils.test.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,33 +35,23 @@ import { ExactModule } from '@jspm/generator/lib/install/package';
3535

3636
test("ensureDirSync has dir", () => {
3737
const dir = "/path/to/dir";
38-
const existsSyncMock = jest.spyOn(fs, 'existsSync').mockReturnValue(true);
3938
const dirnameMock = jest.spyOn(path, 'dirname')
4039
ensureDirSync(dir);
41-
expect(existsSyncMock).toBeCalledWith(dir);
4240
expect(dirnameMock).not.toBeCalled();
4341
});
4442

4543
test("ensureDirSync has parent dir", () => {
4644
const dir = "/path/to/dir";
47-
const existsSyncMock = jest.spyOn(fs, 'existsSync').mockReturnValue(false);
48-
const dirnameMock = jest.spyOn(path, 'dirname').mockReturnValue("/path/to/dir");
4945
const mkdirSyncMock = jest.spyOn(fs, 'mkdirSync')
5046
ensureDirSync(dir);
51-
expect(existsSyncMock).toBeCalledWith(dir);
52-
expect(dirnameMock).toBeCalledWith(dir);
5347
expect(mkdirSyncMock).toHaveBeenCalledTimes(1);
5448
});
5549

5650
test("ensureDirSync to have recursion", () => {
5751
const dir = "/path/to/dir";
58-
const existsSyncMock = jest.spyOn(fs, 'existsSync').mockReturnValue(false);
59-
const dirnameMock = jest.spyOn(path, 'dirname').mockReturnValue("/path/");
6052
const mkdirSyncMock = jest.spyOn(fs, 'mkdirSync')
6153
ensureDirSync(dir);
62-
expect(existsSyncMock).toBeCalledWith(dir);
63-
expect(dirnameMock).toBeCalledWith(dir);
64-
expect(mkdirSyncMock).toHaveBeenCalledTimes(2);
54+
expect(mkdirSyncMock).toHaveBeenCalledTimes(1);
6555
});
6656

6757
test("ensureFileSync has file", () => {

src/config.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { existsSync, readFileSync } from "node:fs";
1+
import { existsSync, readFileSync, mkdirSync } from "node:fs";
22
import { join } from "node:path";
33
import { fileURLToPath } from "node:url";
44
import { ImportMap } from "@jspm/import-map";
@@ -20,6 +20,8 @@ export const root = fileURLToPath(`file://${wd}`);
2020
export const cacheMap = new Map();
2121
export const nodeImportMapPath = join(root, "node.importmap");
2222
export const cache = join(root, ".cache");
23+
const hasCacheFoler = existsSync(cache);
24+
if (!hasCacheFoler) mkdirSync(cache);
2325
const map = existsSync(nodeImportMapPath) ? JSON.parse(readFileSync(nodeImportMapPath, { encoding: "utf8" })) : {};
2426
export const importmap = new ImportMap({ rootUrl: import.meta.url, map });
2527

src/utils.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,18 @@ import { logger } from "./logger";
1919
const log = logger({ file: "loader", isLogging });
2020

2121
export const ensureDirSync = (dirPath: string) => {
22-
if (existsSync(dirPath)) return;
23-
const parentDir = dirname(dirPath);
24-
if (parentDir !== dirPath) ensureDirSync(parentDir);
25-
mkdirSync(dirPath);
22+
try {
23+
mkdirSync(dirPath, { recursive: true });
24+
} catch (err) {
25+
log.error(`ensureDirSync: Failed in creating ${dirPath}`, { error: err });
26+
throw err;
27+
}
2628
};
2729

2830
export const ensureFileSync = (path: string) => {
29-
const dirPath = dirname(path);
30-
if (!existsSync(dirPath)) ensureDirSync(dirPath);
3131
try {
32+
const dirPath = dirname(path);
33+
if (!existsSync(dirPath)) ensureDirSync(dirPath);
3234
writeFileSync(path, "", { flag: "wx" });
3335
} catch {
3436
log.error(`ensureDirSync: Failed in creating ${path}`);

tests/e2e/test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
import * as TeleportProjectGeneratorPreact from "@teleporthq/teleport-project-generator-preact";
2-
import * as TeleportProjectGeneratorReact from "@teleporthq/teleport-project-generator-react";
3-
import * as TeleportTypes from "@teleporthq/teleport-types";
1+
// import * as TeleportProjectGeneratorPreact from "@teleporthq/teleport-project-generator-preact";
2+
// import * as TeleportProjectGeneratorReact from "@teleporthq/teleport-project-generator-react";
3+
// import * as TeleportTypes from "@teleporthq/teleport-types";
44
import * as react from "react";
55
import * as reactRouter from "react-router";
66
import * as reactRouterDom from "react-router-dom";
77
import assert from "assert";
88

99
// Write main module code here, or as a separate file with a "src" attribute on the module script.
1010
console.log(
11-
TeleportProjectGeneratorPreact,
12-
TeleportProjectGeneratorReact,
13-
TeleportTypes,
11+
// TeleportProjectGeneratorPreact,
12+
// TeleportProjectGeneratorReact,
13+
// TeleportTypes,
1414
react,
1515
reactRouter,
1616
reactRouterDom,

0 commit comments

Comments
 (0)