-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dynamically import smol-toml package (#9463)
* dynamically import smol-toml package * fixed prettier * wait for the module to be loaded explicitly * fixed style * addressing PR feedback
- Loading branch information
1 parent
db2c9b0
commit 7b8ce24
Showing
8 changed files
with
67 additions
and
15 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
19 changes: 19 additions & 0 deletions
19
packages/pyright-internal/src/common/asyncInitialization.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,19 @@ | ||
/* | ||
* shared.ts | ||
* Copyright (c) Microsoft Corporation. | ||
* Licensed under the MIT license. | ||
* | ||
* helpers shared between multiple packages such as pyright-internal and pyright | ||
*/ | ||
|
||
import { ensureTomlModuleLoaded } from './tomlUtils'; | ||
|
||
export async function initializeDependencies() { | ||
// Ensure dynamic imports are loaded. | ||
await ensureTomlModuleLoaded(); | ||
|
||
if (process.env.NODE_ENV === 'production') { | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
require('source-map-support').install(); | ||
} | ||
} |
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,34 @@ | ||
/* | ||
* tomlUtils.ts | ||
* Copyright (c) Microsoft Corporation. | ||
* Licensed under the MIT license. | ||
* | ||
* helpers related to TOML | ||
*/ | ||
|
||
type TomlPrimitive = | ||
| string | ||
| number | ||
| boolean | ||
| { | ||
[key: string]: TomlPrimitive; | ||
} | ||
| TomlPrimitive[]; | ||
|
||
// Dynamically load `smol-toml` to address module loading issues and | ||
// maintain existing module resolution to support multiple environments. | ||
let TOML: any; | ||
const loadTomlModule = (async () => { | ||
TOML = await import('smol-toml'); | ||
})(); | ||
|
||
export async function ensureTomlModuleLoaded() { | ||
await loadTomlModule; | ||
} | ||
|
||
export const parse = (toml: string): Record<string, TomlPrimitive> => { | ||
if (!TOML) { | ||
throw new Error('TOML module not loaded'); | ||
} | ||
return TOML.parse(toml); | ||
}; |
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
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