@inlang/sdk 0.10.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapter/solidAdapter.test.js +12 -8
- package/dist/createNodeishFsWithAbsolutePaths.d.ts +13 -0
- package/dist/createNodeishFsWithAbsolutePaths.d.ts.map +1 -0
- package/dist/createNodeishFsWithAbsolutePaths.js +29 -0
- package/dist/createNodeishFsWithAbsolutePaths.test.d.ts +2 -0
- package/dist/createNodeishFsWithAbsolutePaths.test.d.ts.map +1 -0
- package/dist/createNodeishFsWithAbsolutePaths.test.js +37 -0
- package/dist/errors.d.ts +5 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +6 -0
- package/dist/loadProject.d.ts +4 -1
- package/dist/loadProject.d.ts.map +1 -1
- package/dist/loadProject.js +18 -5
- package/dist/loadProject.test.js +134 -44
- package/dist/resolve-modules/import.d.ts.map +1 -1
- package/dist/resolve-modules/import.js +3 -2
- package/dist/resolve-modules/plugins/types.d.ts +2 -2
- package/dist/resolve-modules/plugins/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/adapter/solidAdapter.test.ts +12 -8
- package/src/createNodeishFsWithAbsolutePaths.test.ts +47 -0
- package/src/createNodeishFsWithAbsolutePaths.ts +40 -0
- package/src/errors.ts +7 -0
- package/src/loadProject.test.ts +148 -43
- package/src/loadProject.ts +25 -4
- package/src/resolve-modules/import.ts +3 -2
- package/src/resolve-modules/plugins/types.ts +2 -2
package/src/loadProject.ts
CHANGED
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
ProjectSettingsInvalidError,
|
|
14
14
|
PluginLoadMessagesError,
|
|
15
15
|
PluginSaveMessagesError,
|
|
16
|
+
LoadProjectInvalidArgument,
|
|
16
17
|
} from "./errors.js"
|
|
17
18
|
import { createRoot, createSignal, createEffect } from "./reactivity/solid.js"
|
|
18
19
|
import { createMessagesQuery } from "./createMessagesQuery.js"
|
|
@@ -21,14 +22,21 @@ import { createMessageLintReportsQuery } from "./createMessageLintReportsQuery.j
|
|
|
21
22
|
import { ProjectSettings, Message, type NodeishFilesystemSubset } from "./versionedInterfaces.js"
|
|
22
23
|
import { tryCatch, type Result } from "@inlang/result"
|
|
23
24
|
import { migrateIfOutdated } from "@inlang/project-settings/migration"
|
|
25
|
+
import {
|
|
26
|
+
createNodeishFsWithAbsolutePaths,
|
|
27
|
+
isAbsolutePath,
|
|
28
|
+
} from "./createNodeishFsWithAbsolutePaths.js"
|
|
24
29
|
|
|
25
30
|
const settingsCompiler = TypeCompiler.Compile(ProjectSettings)
|
|
26
31
|
|
|
27
32
|
/**
|
|
28
33
|
* Creates an inlang instance.
|
|
29
34
|
*
|
|
30
|
-
* -
|
|
35
|
+
* @param settingsFilePath - Absolute path to the inlang settings file.
|
|
36
|
+
* @param nodeishFs - Filesystem that implements the NodeishFilesystemSubset interface.
|
|
37
|
+
* @param _import - Use `_import` to pass a custom import function for testing,
|
|
31
38
|
* and supporting legacy resolvedModules such as CJS.
|
|
39
|
+
* @param _capture - Use `_capture` to capture events for analytics.
|
|
32
40
|
*
|
|
33
41
|
*/
|
|
34
42
|
export const loadProject = async (args: {
|
|
@@ -37,14 +45,27 @@ export const loadProject = async (args: {
|
|
|
37
45
|
_import?: ImportFunction
|
|
38
46
|
_capture?: (id: string, props: Record<string, unknown>) => void
|
|
39
47
|
}): Promise<InlangProject> => {
|
|
48
|
+
// -- validation --------------------------------------------------------
|
|
49
|
+
//! the only place where throwing is acceptable because the project
|
|
50
|
+
//! won't even be loaded. do not throw anywhere else. otherwise, apps
|
|
51
|
+
//! can't handle errors gracefully.
|
|
52
|
+
if (!isAbsolutePath(args.settingsFilePath)) {
|
|
53
|
+
throw new LoadProjectInvalidArgument(
|
|
54
|
+
`Expected an absolute path but received "${args.settingsFilePath}".`,
|
|
55
|
+
{ argument: "settingsFilePath" }
|
|
56
|
+
)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// -- load project ------------------------------------------------------
|
|
40
60
|
return await createRoot(async () => {
|
|
41
61
|
const [initialized, markInitAsComplete, markInitAsFailed] = createAwaitable()
|
|
62
|
+
const nodeishFs = createNodeishFsWithAbsolutePaths(args)
|
|
42
63
|
|
|
43
64
|
// -- settings ------------------------------------------------------------
|
|
44
65
|
|
|
45
66
|
const [settings, _setSettings] = createSignal<ProjectSettings>()
|
|
46
67
|
createEffect(() => {
|
|
47
|
-
loadSettings({ settingsFilePath: args.settingsFilePath, nodeishFs
|
|
68
|
+
loadSettings({ settingsFilePath: args.settingsFilePath, nodeishFs })
|
|
48
69
|
.then((settings) => {
|
|
49
70
|
setSettings(settings)
|
|
50
71
|
// rename settings to get a convenient access to the data in Posthog
|
|
@@ -58,7 +79,7 @@ export const loadProject = async (args: {
|
|
|
58
79
|
// TODO: create FS watcher and update settings on change
|
|
59
80
|
|
|
60
81
|
const writeSettingsToDisk = skipFirst((settings: ProjectSettings) =>
|
|
61
|
-
_writeSettingsToDisk({ nodeishFs
|
|
82
|
+
_writeSettingsToDisk({ nodeishFs, settings })
|
|
62
83
|
)
|
|
63
84
|
|
|
64
85
|
const setSettings = (settings: ProjectSettings): Result<void, ProjectSettingsInvalidError> => {
|
|
@@ -88,7 +109,7 @@ export const loadProject = async (args: {
|
|
|
88
109
|
const _settings = settings()
|
|
89
110
|
if (!_settings) return
|
|
90
111
|
|
|
91
|
-
resolveModules({ settings: _settings, nodeishFs
|
|
112
|
+
resolveModules({ settings: _settings, nodeishFs, _import: args._import })
|
|
92
113
|
.then((resolvedModules) => {
|
|
93
114
|
setResolvedModules(resolvedModules)
|
|
94
115
|
})
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import dedent from "dedent"
|
|
2
|
-
import { normalizePath } from "@lix-js/fs"
|
|
3
2
|
import type { NodeishFilesystemSubset } from "@inlang/plugin"
|
|
4
3
|
import { ModuleImportError } from "./errors.js"
|
|
5
4
|
|
|
@@ -42,7 +41,9 @@ async function $import(
|
|
|
42
41
|
if (uri.startsWith("http")) {
|
|
43
42
|
moduleAsText = await (await fetch(uri)).text()
|
|
44
43
|
} else {
|
|
45
|
-
moduleAsText = await options.readFile(
|
|
44
|
+
moduleAsText = await options.readFile(uri, {
|
|
45
|
+
encoding: "utf-8",
|
|
46
|
+
})
|
|
46
47
|
}
|
|
47
48
|
|
|
48
49
|
const moduleWithMimeType = "data:application/javascript," + encodeURIComponent(moduleAsText)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { NodeishFilesystem
|
|
1
|
+
import type { NodeishFilesystem } from "@lix-js/fs"
|
|
2
2
|
import type {
|
|
3
3
|
PluginReturnedInvalidCustomApiError,
|
|
4
4
|
PluginLoadMessagesFunctionAlreadyDefinedError,
|
|
@@ -18,7 +18,7 @@ import type { ProjectSettings } from "@inlang/project-settings"
|
|
|
18
18
|
* - only uses minimally required functions to decrease the API footprint on the ecosystem.
|
|
19
19
|
*/
|
|
20
20
|
export type NodeishFilesystemSubset = Pick<
|
|
21
|
-
|
|
21
|
+
NodeishFilesystem,
|
|
22
22
|
"readFile" | "readdir" | "mkdir" | "writeFile"
|
|
23
23
|
>
|
|
24
24
|
|