forked from podman-desktop/podman-desktop
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: handle property the watch mode for extension in development mode (…
…podman-desktop#10623) * fix: handle property the watch mode for extension in development mode fixes podman-desktop#10619 Signed-off-by: Florent Benoit <[email protected]>
- Loading branch information
Showing
9 changed files
with
565 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
packages/main/src/plugin/extension-tsconfig-parser.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/********************************************************************** | ||
* Copyright (C) 2025 Red Hat, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
***********************************************************************/ | ||
|
||
import { existsSync } from 'node:fs'; | ||
import { sep } from 'node:path'; | ||
|
||
import type { FileMatcher, TsConfigResult } from 'get-tsconfig'; | ||
import { createFilesMatcher, getTsconfig } from 'get-tsconfig'; | ||
import { beforeEach, expect, test, vi } from 'vitest'; | ||
|
||
import { ExtensionTypeScriptConfigParser } from './extension-tsconfig-parser.js'; | ||
|
||
vi.mock('node:fs'); | ||
vi.mock('get-tsconfig'); | ||
|
||
beforeEach(() => { | ||
vi.restoreAllMocks(); | ||
vi.resetAllMocks(); | ||
}); | ||
|
||
test('no tsconfig.json file means it returns undefined', async () => { | ||
const fakePath = 'fakePath'; | ||
const extensionTypeScriptConfigParser = new ExtensionTypeScriptConfigParser(fakePath); | ||
|
||
const result = await extensionTypeScriptConfigParser.analyze(); | ||
|
||
expect(existsSync).toHaveBeenCalledWith(expect.stringContaining(`fakePath${sep}tsconfig.json`)); | ||
expect(vi.mocked(getTsconfig)).not.toHaveBeenCalled(); | ||
expect(result).toBe(undefined); | ||
}); | ||
|
||
test('with a tsconfig.json file means it returns undefined', async () => { | ||
vi.mocked(existsSync).mockReturnValue(true); | ||
const fakePath = 'fakePath'; | ||
const extensionTypeScriptConfigParser = new ExtensionTypeScriptConfigParser(fakePath); | ||
|
||
const fakeTsConfig = {} as unknown as TsConfigResult; | ||
const fakeFilesMatcher = {} as unknown as FileMatcher; | ||
vi.mocked(getTsconfig).mockReturnValue(fakeTsConfig); | ||
vi.mocked(createFilesMatcher).mockReturnValue(fakeFilesMatcher); | ||
|
||
const result = await extensionTypeScriptConfigParser.analyze(); | ||
expect(existsSync).toHaveBeenCalledWith(expect.stringContaining(`fakePath${sep}tsconfig.json`)); | ||
|
||
// check we called the getTsconfig function | ||
expect(vi.mocked(getTsconfig)).toHaveBeenCalled(); | ||
|
||
// check we called the createFilesMatcher function | ||
expect(vi.mocked(createFilesMatcher)).toHaveBeenCalledWith(fakeTsConfig); | ||
|
||
// check we have a valid file matcher in that case | ||
expect(result).toBe(fakeFilesMatcher); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/********************************************************************** | ||
* Copyright (C) 2025 Red Hat, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
***********************************************************************/ | ||
|
||
import { existsSync } from 'node:fs'; | ||
import { resolve } from 'node:path'; | ||
|
||
import type { FileMatcher } from 'get-tsconfig'; | ||
import { createFilesMatcher, getTsconfig } from 'get-tsconfig'; | ||
|
||
/** | ||
* Responsible to parse all the tsconfig.json files from an extension | ||
* and provide a list of all pattern having source files | ||
*/ | ||
export class ExtensionTypeScriptConfigParser { | ||
#rootPath: string; | ||
|
||
constructor(rootPath: string) { | ||
this.#rootPath = rootPath; | ||
} | ||
|
||
async analyze(): Promise<FileMatcher | undefined> { | ||
// read all tsconfig.json files not being in node_modules | ||
// and parse them to extract all the patterns | ||
|
||
// find all tsconfig.json files from rootPath folder | ||
// do we have a tsconfig.json file in the rootPath ? | ||
const tsConfigJsonPath = resolve(this.#rootPath, 'tsconfig.json'); | ||
|
||
if (existsSync(tsConfigJsonPath)) { | ||
const tsConfig = getTsconfig(tsConfigJsonPath); | ||
if (tsConfig) { | ||
return createFilesMatcher(tsConfig); | ||
} | ||
} | ||
return undefined; | ||
} | ||
} |
Oops, something went wrong.