@observablehq/notebook-kit 1.7.4 → 1.7.5
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/package.json
CHANGED
|
@@ -113,7 +113,15 @@ export declare class NotebookRuntime {
|
|
|
113
113
|
Mutable: () => typeof import("./stdlib/mutable.js").Mutable;
|
|
114
114
|
Promises: () => typeof import("./stdlib/promises/index.js");
|
|
115
115
|
DOM: () => typeof import("./stdlib/dom/index.js");
|
|
116
|
-
require: () =>
|
|
116
|
+
require: () => {
|
|
117
|
+
(...specifiers: unknown[]): Promise<unknown>;
|
|
118
|
+
resolve: (specifier: unknown) => string;
|
|
119
|
+
} & {
|
|
120
|
+
alias: (aliases: Record<string, string>) => {
|
|
121
|
+
(...specifiers: unknown[]): Promise<unknown>;
|
|
122
|
+
resolve: (specifier: unknown) => string;
|
|
123
|
+
};
|
|
124
|
+
};
|
|
117
125
|
__ojs_observer: () => () => import("./stdlib/observer.js").Observer;
|
|
118
126
|
});
|
|
119
127
|
define(state: DefineState, definition: Definition, observer?: typeof observe): void;
|
|
@@ -6,7 +6,6 @@ import { Interpreter } from "./interpreter.js";
|
|
|
6
6
|
import { Mutable } from "./mutable.js";
|
|
7
7
|
import { Observer } from "./observer.js";
|
|
8
8
|
import * as Promises from "./promises/index.js";
|
|
9
|
-
import { require } from "./require.js";
|
|
10
9
|
export declare const root: HTMLElement;
|
|
11
10
|
export declare const library: {
|
|
12
11
|
aapl: () => Promise<any>;
|
|
@@ -103,6 +102,14 @@ export declare const library: {
|
|
|
103
102
|
Mutable: () => typeof Mutable;
|
|
104
103
|
Promises: () => typeof Promises;
|
|
105
104
|
DOM: () => typeof DOM;
|
|
106
|
-
require: () =>
|
|
105
|
+
require: () => {
|
|
106
|
+
(...specifiers: unknown[]): Promise<unknown>;
|
|
107
|
+
resolve: (specifier: unknown) => string;
|
|
108
|
+
} & {
|
|
109
|
+
alias: (aliases: Record<string, string>) => {
|
|
110
|
+
(...specifiers: unknown[]): Promise<unknown>;
|
|
111
|
+
resolve: (specifier: unknown) => string;
|
|
112
|
+
};
|
|
113
|
+
};
|
|
107
114
|
__ojs_observer: () => () => Observer;
|
|
108
115
|
};
|
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
export declare
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}
|
|
1
|
+
export declare const require: {
|
|
2
|
+
(...specifiers: unknown[]): Promise<unknown>;
|
|
3
|
+
resolve: (specifier: unknown) => string;
|
|
4
|
+
} & {
|
|
5
|
+
alias: typeof alias;
|
|
6
|
+
};
|
|
7
|
+
declare function alias(aliases: Record<string, string>): {
|
|
8
|
+
(...specifiers: unknown[]): Promise<unknown>;
|
|
9
|
+
resolve: (specifier: unknown) => string;
|
|
10
|
+
};
|
|
11
|
+
export {};
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
require.resolve = resolve;
|
|
2
1
|
const cache = new WeakMap();
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
export const require = Object.assign(Requirer(resolve), { alias });
|
|
3
|
+
function Requirer(resolve) {
|
|
4
|
+
async function require(...specifiers) {
|
|
5
|
+
return specifiers.length === 1
|
|
6
|
+
? import(/* @vite-ignore */ resolve(specifiers[0])).then(objectify)
|
|
7
|
+
: Promise.all(specifiers.map((s) => require(s))).then(merge);
|
|
8
|
+
}
|
|
9
|
+
require.resolve = resolve;
|
|
10
|
+
return require;
|
|
7
11
|
}
|
|
8
12
|
function parseNpmSpecifier(specifier) {
|
|
9
13
|
const parts = specifier.split("/");
|
|
@@ -16,6 +20,13 @@ function parseNpmSpecifier(specifier) {
|
|
|
16
20
|
const path = parts.length > 0 ? `/${parts.join("/")}` : "";
|
|
17
21
|
return { name, range, path };
|
|
18
22
|
}
|
|
23
|
+
function alias(aliases) {
|
|
24
|
+
return Requirer((specifier) => {
|
|
25
|
+
if (specifier in aliases)
|
|
26
|
+
specifier = aliases[specifier];
|
|
27
|
+
return resolve(specifier);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
19
30
|
function resolve(_specifier) {
|
|
20
31
|
const specifier = String(_specifier);
|
|
21
32
|
if (isProtocol(specifier) || isLocal(specifier))
|
|
@@ -37,6 +48,9 @@ function objectify(module) {
|
|
|
37
48
|
cache.set(module, (object = defaultify(module)));
|
|
38
49
|
return object;
|
|
39
50
|
}
|
|
51
|
+
function merge(modules) {
|
|
52
|
+
return Object.assign({}, ...modules);
|
|
53
|
+
}
|
|
40
54
|
/** Returns true for e.g. https://example.com/ */
|
|
41
55
|
function isProtocol(specifier) {
|
|
42
56
|
return /^\w+:/.test(specifier);
|