Skip to content

Commit

Permalink
dynamically import smol-toml package
Browse files Browse the repository at this point in the history
  • Loading branch information
heejaechang committed Nov 14, 2024
1 parent db2c9b0 commit f5e93a1
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/pyright-internal/src/analyzer/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
*/

import * as JSONC from 'jsonc-parser';
import { parse } from 'smol-toml';
import { AbstractCancellationTokenSource, CancellationToken } from 'vscode-languageserver';
import { parse } from '../common/tomlUtils';

import { BackgroundAnalysisBase, RefreshOptions } from '../backgroundAnalysisBase';
import { CancellationProvider, DefaultCancellationProvider } from '../common/cancellationUtils';
Expand Down
25 changes: 25 additions & 0 deletions packages/pyright-internal/src/common/tomlUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* 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;
(async () => {
TOML = await import('smol-toml');
})();

export const parse = (toml: string): Record<string, TomlPrimitive> => {
if (!TOML) {
throw new Error('TOML module not loaded');
}
return TOML.parse(toml);
};
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"target": "es2019",
"module": "preserve",
"module": "node16",
"lib": [
"es2019"
],
Expand All @@ -10,7 +10,7 @@
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"moduleResolution": "Bundler",
"moduleResolution": "node16",
"resolveJsonModule": true,
"sourceMap": true,
"outDir": "./out",
Expand Down

0 comments on commit f5e93a1

Please sign in to comment.