Skip to content

Commit acd2695

Browse files
committed
refactor: remove route path builtin imports
1 parent e42995e commit acd2695

5 files changed

Lines changed: 37 additions & 50 deletions

packages/insomnia/config/renderer-node-import-baseline.json

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,6 @@
160160
"importer": "src/plugins/index.ts",
161161
"builtin": "path"
162162
},
163-
{
164-
"importer": "src/routes/import.scan.tsx",
165-
"builtin": "path"
166-
},
167163
{
168164
"importer": "src/routes/organization.$organizationId.project.$projectId.workspace.$workspaceId.debug.request.$requestId.send.tsx",
169165
"builtin": "fs"
@@ -172,14 +168,6 @@
172168
"importer": "src/routes/organization.$organizationId.project.$projectId.workspace.$workspaceId.debug.request.$requestId.send.tsx",
173169
"builtin": "path"
174170
},
175-
{
176-
"importer": "src/routes/organization.$organizationId.project.$projectId.workspace.$workspaceId.spec.generate-request-collection.tsx",
177-
"builtin": "path"
178-
},
179-
{
180-
"importer": "src/routes/organization.$organizationId.project.$projectId.workspace.$workspaceId.spec.tsx",
181-
"builtin": "path"
182-
},
183171
{
184172
"importer": "src/routes/organization.$organizationId.project.$projectId.workspace.new.tsx",
185173
"builtin": "fs"
@@ -188,10 +176,6 @@
188176
"importer": "src/routes/organization.$organizationId.project.$projectId.workspace.new.tsx",
189177
"builtin": "path"
190178
},
191-
{
192-
"importer": "src/routes/organization.$organizationId.project.$projectId.workspace.update.tsx",
193-
"builtin": "path"
194-
},
195179
{
196180
"importer": "src/script-executor.ts",
197181
"builtin": "fs/promises"

packages/insomnia/src/routes/import.scan.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import path from 'node:path';
2-
31
import { type ActionFunctionArgs, href } from 'react-router';
42

53
import type { ImportSourceType, ScanResult } from '~/common/import';
@@ -24,6 +22,7 @@ export const scanImportResources = async (data: {
2422
postmanArchiveFile?: string | null;
2523
}): Promise<ScanResult[]> => {
2624
const { source, postmanArchiveFile } = data;
25+
const isZipFilePath = (filePath: string) => filePath.toLowerCase().endsWith('.zip');
2726

2827
invariant(typeof source === 'string', 'Source is required.');
2928
invariant(IMPORT_SOURCE_TYPES.includes(source), 'Unsupported import type');
@@ -74,8 +73,8 @@ export const scanImportResources = async (data: {
7473
throw new Error('File is required');
7574
}
7675

77-
const zipFilePaths = filePaths.filter(filePath => path.extname(filePath) === '.zip');
78-
const nonZipFilePaths = filePaths.filter(filePath => path.extname(filePath) !== '.zip');
76+
const zipFilePaths = filePaths.filter(isZipFilePath);
77+
const nonZipFilePaths = filePaths.filter(filePath => !isZipFilePath(filePath));
7978

8079
// zip file is for postman data dump
8180
for (const zipFilePath of zipFilePaths) {
@@ -84,7 +83,7 @@ export const scanImportResources = async (data: {
8483
function trans({ contentStr, oriFileName }: ImportEntry): ImportEntry {
8584
return {
8685
contentStr,
87-
oriFileName: `${oriFileName} in ${path.basename(zipFilePath)}`,
86+
oriFileName: `${oriFileName} in ${window.path.basename(zipFilePath)}`,
8887
};
8988
}
9089

@@ -131,7 +130,7 @@ export const scanImportResources = async (data: {
131130

132131
contentList.push({
133132
contentStr,
134-
oriFileName: path.basename(filePath),
133+
oriFileName: window.path.basename(filePath),
135134
oriFilePath: filePath,
136135
});
137136
}

packages/insomnia/src/routes/organization.$organizationId.project.$projectId.workspace.$workspaceId.spec.generate-request-collection.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import path from 'node:path';
2-
31
import type { IRuleResult } from '@stoplight/spectral-core';
42
import { href, redirect } from 'react-router';
53

@@ -29,10 +27,12 @@ export async function clientAction({ params }: Route.ClientActionArgs) {
2927

3028
const isLintError = (result: IRuleResult) => result.severity === 0;
3129

32-
const gitRepositoryId = models.project.isGitProject(project) ? project.gitRepositoryId : workspaceMeta?.gitRepositoryId;
30+
const gitRepositoryId = models.project.isGitProject(project)
31+
? project.gitRepositoryId
32+
: workspaceMeta?.gitRepositoryId;
3333

3434
const rulesetPath = gitRepositoryId
35-
? path.join(window.app.getPath('userData'), `version-control/git/${gitRepositoryId}/other/.spectral.yaml`)
35+
? window.path.join(window.app.getPath('userData'), `version-control/git/${gitRepositoryId}/other/.spectral.yaml`)
3636
: '';
3737

3838
const { diagnostics, error } = await window.main.lintSpec({ documentContent: apiSpec.contents, rulesetPath });

packages/insomnia/src/routes/organization.$organizationId.project.$projectId.workspace.$workspaceId.spec.tsx

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import path from 'node:path';
2-
31
import { type IRuleResult } from '@stoplight/spectral-core';
42
import CodeMirror from 'codemirror';
53
import type { OpenAPIV3 } from 'openapi-types';
@@ -86,11 +84,13 @@ export async function clientLoader({ params }: Route.ClientLoaderArgs) {
8684

8785
const workspaceMeta = await services.workspaceMeta.getByParentId(workspaceId);
8886

89-
const gitRepositoryId = models.project.isGitProject(project) ? project.gitRepositoryId : workspaceMeta?.gitRepositoryId;
87+
const gitRepositoryId = models.project.isGitProject(project)
88+
? project.gitRepositoryId
89+
: workspaceMeta?.gitRepositoryId;
9090
// we don't run the lint here because it is expensive and slows first render too much
9191
// TODO: add this in once we run this loader outside the renderer
9292
const rulesetPath = gitRepositoryId
93-
? path.join(window.app.getPath('userData'), `version-control/git/${gitRepositoryId}/other/.spectral.yaml`)
93+
? window.path.join(window.app.getPath('userData'), `version-control/git/${gitRepositoryId}/other/.spectral.yaml`)
9494
: '';
9595

9696
let parsedSpec: OpenAPIV3.Document | undefined;
@@ -373,8 +373,7 @@ const Component = ({ params }: Route.ComponentProps) => {
373373
let parsedSpec: string | undefined;
374374
try {
375375
// yaml parses json correctly
376-
parsedSpec = YAML.parse(editorValue)
377-
376+
parsedSpec = YAML.parse(editorValue);
378377
} catch {
379378
showToast({
380379
title: 'Failed to convert spec format',
@@ -387,8 +386,7 @@ const Component = ({ params }: Route.ComponentProps) => {
387386
const contents = to === 'json' ? JSON.stringify(parsedSpec, null, 2) : YAML.stringify(parsedSpec);
388387
editor.current?.setValue(contents);
389388
updateApiSpec({ organizationId, projectId, workspaceId, contents });
390-
391-
}
389+
};
392390

393391
const specActionList: SpecActionItem[] = [
394392
{
@@ -417,17 +415,25 @@ const Component = ({ params }: Route.ComponentProps) => {
417415
setIsSpecPaneOpen(!isSpecPaneOpen);
418416
},
419417
},
420-
...(specFormat === 'json' ? [{
421-
id: 'convert-to-yaml',
422-
name: 'Convert to YAML',
423-
icon: <Icon className="w-3" icon="sync-alt" />,
424-
action: () => switchFormat('yaml'),
425-
}] : specFormat === 'yaml' ? [{
426-
id: 'convert-to-json',
427-
name: 'Convert to JSON',
428-
icon: <Icon className="w-3" icon="sync-alt" />,
429-
action: () => switchFormat('json'),
430-
}] : []),
418+
...(specFormat === 'json'
419+
? [
420+
{
421+
id: 'convert-to-yaml',
422+
name: 'Convert to YAML',
423+
icon: <Icon className="w-3" icon="sync-alt" />,
424+
action: () => switchFormat('yaml'),
425+
},
426+
]
427+
: specFormat === 'yaml'
428+
? [
429+
{
430+
id: 'convert-to-json',
431+
name: 'Convert to JSON',
432+
icon: <Icon className="w-3" icon="sync-alt" />,
433+
action: () => switchFormat('json'),
434+
},
435+
]
436+
: []),
431437
];
432438

433439
const disabledKeys = specActionList.filter(item => item.isDisabled).map(item => item.id);

packages/insomnia/src/routes/organization.$organizationId.project.$projectId.workspace.update.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import path from 'node:path';
2-
31
import { href } from 'react-router';
42

53
import { models, services } from '~/insomnia-data';
@@ -69,15 +67,15 @@ export async function clientAction({ request }: Route.ClientActionArgs) {
6967
if (models.project.isGitProject(project)) {
7068
const workspaceMeta = await services.workspaceMeta.getOrCreateByParentId(workspace._id);
7169

72-
const existingPathDir = path.dirname(workspaceMeta.gitFilePath || '');
73-
let fileName = path.basename(workspaceMeta.gitFilePath || '');
70+
const existingPathDir = window.path.dirname(workspaceMeta.gitFilePath || '');
71+
let fileName = window.path.basename(workspaceMeta.gitFilePath || '');
7472

7573
if (patch.fileName && typeof patch.fileName === 'string') {
7674
fileName = patch.fileName;
7775
}
7876

7977
await services.workspaceMeta.update(workspaceMeta, {
80-
gitFilePath: path.join(existingPathDir, safeToUseInsomniaFileNameWithExt(fileName)),
78+
gitFilePath: window.path.join(existingPathDir, safeToUseInsomniaFileNameWithExt(fileName)),
8179
});
8280
}
8381

0 commit comments

Comments
 (0)