repl-sdk 0.0.0 → 1.0.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/assets/tar-worker-kdkltuRC.js +598 -0
- package/dist/assets/tar-worker-kdkltuRC.js.map +1 -0
- package/dist/codemirror-D4aIVflZ.js +110 -0
- package/dist/codemirror-D4aIVflZ.js.map +1 -0
- package/dist/gjs-CzFzkEFv.js +173 -0
- package/dist/gjs-CzFzkEFv.js.map +1 -0
- package/dist/gmd-D9OXs2v3.js +166 -0
- package/dist/gmd-D9OXs2v3.js.map +1 -0
- package/dist/hbs-CuhWjffM.js +62 -0
- package/dist/hbs-CuhWjffM.js.map +1 -0
- package/dist/index-CUWCqMoD.js +2133 -0
- package/dist/index-CUWCqMoD.js.map +1 -0
- package/dist/index.js +4 -104
- package/dist/index.js.map +1 -1
- package/dist/parse-aBKk9rfS.js +328 -0
- package/dist/parse-aBKk9rfS.js.map +1 -0
- package/dist/render-app-island-B-i8rvGi.js +61 -0
- package/dist/render-app-island-B-i8rvGi.js.map +1 -0
- package/package.json +82 -9
- package/src/cache.js +138 -0
- package/src/cdn.js +93 -0
- package/src/codemirror.js +161 -0
- package/src/compilers/ember/gjs.js +212 -0
- package/src/compilers/ember/gmd.js +190 -0
- package/src/compilers/ember/hbs.js +98 -0
- package/src/compilers/ember/render-app-island.js +83 -0
- package/src/compilers/ember.js +166 -0
- package/src/compilers/js.js +32 -0
- package/src/compilers/markdown/build-compiler.js +151 -0
- package/src/compilers/markdown/const.js +2 -0
- package/src/compilers/markdown/heading-id.js +75 -0
- package/src/compilers/markdown/live-code-extraction.js +198 -0
- package/src/compilers/markdown/parse.js +22 -0
- package/src/compilers/markdown/parse.test.ts +363 -0
- package/src/compilers/markdown/sanitize-for-glimmer.js +26 -0
- package/src/compilers/markdown/types.ts +21 -0
- package/src/compilers/markdown/utils.js +78 -0
- package/src/compilers/markdown.js +125 -0
- package/src/compilers/mermaid.js +35 -0
- package/src/compilers/react.js +47 -0
- package/src/compilers/svelte.js +116 -0
- package/src/compilers/vue.js +58 -0
- package/src/compilers.js +108 -0
- package/src/es-module-shim.js +53 -0
- package/src/index.d.ts +53 -4
- package/src/index.js +744 -89
- package/src/npm.js +58 -0
- package/src/request.Request.test.ts +59 -0
- package/src/request.js +140 -0
- package/src/resolve.fromImports.test.ts +35 -0
- package/src/resolve.fromInternalImport.test.ts +69 -0
- package/src/resolve.js +352 -0
- package/src/resolve.resolvePath.test.ts +24 -0
- package/src/resolve.test.ts +23 -0
- package/src/specifier.js +71 -0
- package/src/specifier.test.ts +90 -0
- package/src/tar-worker.js +61 -0
- package/src/tar.js +76 -0
- package/src/types.ts +335 -58
- package/src/utils.js +28 -1
- package/declarations/index.d.ts +0 -73
package/src/npm.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import packageNameRegex from 'package-name-regex';
|
|
2
|
+
|
|
3
|
+
import { cache } from './cache.js';
|
|
4
|
+
import { assert } from './utils.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @type {Map<string, unknown>} namp@version => manifest
|
|
8
|
+
*/
|
|
9
|
+
const npmInfoCache = new Map();
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @param {string} name
|
|
13
|
+
* @param {string} version
|
|
14
|
+
*/
|
|
15
|
+
export async function getNPMInfo(name, version) {
|
|
16
|
+
const key = `${name}@${version}`;
|
|
17
|
+
|
|
18
|
+
assert(`Must pass valid npm-compatible package name`, packageNameRegex.test(name));
|
|
19
|
+
|
|
20
|
+
const existing = npmInfoCache.get(key);
|
|
21
|
+
|
|
22
|
+
if (existing) {
|
|
23
|
+
return existing;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return cache.cachedPromise(`getNPMInfo:${key}`, async () => {
|
|
27
|
+
assert(`Cannot get data from NPM without specifying the name of the package`, name);
|
|
28
|
+
assert(`Version is required. It may be 'latest'`, version);
|
|
29
|
+
|
|
30
|
+
const response = await fetch(`https://registry.npmjs.org/${name}`);
|
|
31
|
+
const json = await response.json();
|
|
32
|
+
|
|
33
|
+
npmInfoCache.set(key, json);
|
|
34
|
+
|
|
35
|
+
return json;
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @param {any} npmInfo
|
|
41
|
+
* @param {string} requestedVersion
|
|
42
|
+
*/
|
|
43
|
+
export async function getTarUrl(npmInfo, requestedVersion) {
|
|
44
|
+
const json = npmInfo;
|
|
45
|
+
|
|
46
|
+
if (json.error) {
|
|
47
|
+
throw new Error(json.error);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const tag =
|
|
51
|
+
requestedVersion in json['dist-tags']
|
|
52
|
+
? json['dist-tags'][requestedVersion]
|
|
53
|
+
: (requestedVersion ?? json['dist-tags'].latest);
|
|
54
|
+
|
|
55
|
+
const requested = json.versions[tag];
|
|
56
|
+
|
|
57
|
+
return requested.dist.tarball;
|
|
58
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { expect as errorExpect, it } from 'vitest';
|
|
2
|
+
|
|
3
|
+
const expect = errorExpect.soft;
|
|
4
|
+
|
|
5
|
+
import { getTarRequestId, idFromRequestUrl, Request } from './request.js';
|
|
6
|
+
|
|
7
|
+
it('works with scope', () => {
|
|
8
|
+
const request = Request.of({ to: '@iconify/utils' });
|
|
9
|
+
|
|
10
|
+
expect(request.name).toBe('@iconify/utils');
|
|
11
|
+
expect(request.from).toBe(undefined);
|
|
12
|
+
expect(request.to).toBe('.');
|
|
13
|
+
expect(request.version).toBe('latest');
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('works with parent request id', () => {
|
|
17
|
+
const url = getTarRequestId({ to: 'example-library' });
|
|
18
|
+
const id = idFromRequestUrl(url);
|
|
19
|
+
|
|
20
|
+
const request = Request.of({ to: './lib/index.js', from: id });
|
|
21
|
+
|
|
22
|
+
expect(request.name).toBe('example-library');
|
|
23
|
+
expect(request.version).toBe('latest');
|
|
24
|
+
expect(request.from).toBe(Request.fromRequestId(id));
|
|
25
|
+
expect(request.to).toBe('./lib/index.js');
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('works with version and from', () => {
|
|
29
|
+
const url = getTarRequestId({ to: '@iconify/utils@1.0.0/bar.js' });
|
|
30
|
+
const id = idFromRequestUrl(url);
|
|
31
|
+
const request = Request.fromSpecifier(`./foo.js?from=${id}`);
|
|
32
|
+
|
|
33
|
+
expect(request.name).toBe('@iconify/utils');
|
|
34
|
+
expect(request.from).toBe(Request.fromRequestId(id));
|
|
35
|
+
expect(request.to).toBe('./foo.js');
|
|
36
|
+
expect(request.version).toBe('1.0.0');
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('works with subpath imports', () => {
|
|
40
|
+
const url = getTarRequestId({ to: '@iconify/utils/bar.js' });
|
|
41
|
+
const id = idFromRequestUrl(url);
|
|
42
|
+
const request = Request.fromSpecifier(`#foo/hello.js?from=${id}`);
|
|
43
|
+
|
|
44
|
+
expect(request.name).toBe('@iconify/utils');
|
|
45
|
+
expect(request.from).toBe(Request.fromRequestId(id));
|
|
46
|
+
expect(request.to).toBe('#foo/hello.js');
|
|
47
|
+
expect(request.version).toBe('latest');
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('works with up URLs', () => {
|
|
51
|
+
const url = getTarRequestId({ to: 'hast-util-to-html/utils/foo/bar.js' });
|
|
52
|
+
const id = idFromRequestUrl(url);
|
|
53
|
+
const request = Request.fromSpecifier(`../../utils/siblings.js?from=${id}`);
|
|
54
|
+
|
|
55
|
+
expect(request.name).toBe('hast-util-to-html');
|
|
56
|
+
expect(request.from).toBe(Request.fromRequestId(id));
|
|
57
|
+
expect(request.to).toBe('../../utils/siblings.js');
|
|
58
|
+
expect(request.version).toBe('latest');
|
|
59
|
+
});
|
package/src/request.js
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { cache } from './cache.js';
|
|
2
|
+
import { parseSpecifier } from './specifier.js';
|
|
3
|
+
import { assert, unzippedPrefix } from './utils.js';
|
|
4
|
+
|
|
5
|
+
let requestId = 1;
|
|
6
|
+
|
|
7
|
+
function requestKey() {
|
|
8
|
+
return `repl-request-${requestId++}`;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @param {{ to: string, from?: string }} options
|
|
13
|
+
* @returns {string} the id of the request
|
|
14
|
+
*/
|
|
15
|
+
export function idForRequest({ to, from }) {
|
|
16
|
+
const url = getTarRequestId({ to, from });
|
|
17
|
+
|
|
18
|
+
return idFromRequestUrl(url);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @param {{ to: string, from?: string }} options
|
|
23
|
+
* @returns {string} the URL of the request
|
|
24
|
+
*/
|
|
25
|
+
export function getTarRequestId({ to, from }) {
|
|
26
|
+
const request = Request.of({ to, from });
|
|
27
|
+
|
|
28
|
+
const key = requestKey();
|
|
29
|
+
|
|
30
|
+
cache.requestCache.set(key, request);
|
|
31
|
+
|
|
32
|
+
return `${unzippedPrefix}/${key}`;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @param {string} url
|
|
37
|
+
* @returnns {string}
|
|
38
|
+
*/
|
|
39
|
+
export function idFromRequestUrl(url) {
|
|
40
|
+
return url.replace(unzippedPrefix + '/', '');
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export class Request {
|
|
44
|
+
static get #idCache() {
|
|
45
|
+
return cache.requestCache;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @param {{ to: string, from?: string }} toFrom
|
|
50
|
+
*/
|
|
51
|
+
static of({ to, from }) {
|
|
52
|
+
const isRoot = to.match(/^[A-Za-z@]/);
|
|
53
|
+
const fromId = from?.replace(unzippedPrefix + '/', '');
|
|
54
|
+
const request = Request.fromSpecifier(isRoot ? to : `${to}?from=${fromId}`);
|
|
55
|
+
|
|
56
|
+
return request;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* @param {string} id
|
|
61
|
+
*/
|
|
62
|
+
static fromRequestId(id) {
|
|
63
|
+
const request = Request.#idCache.get(id);
|
|
64
|
+
|
|
65
|
+
assert(`Could not find request from id:${id}`, request);
|
|
66
|
+
|
|
67
|
+
return request;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* @param {string} specifier
|
|
72
|
+
*/
|
|
73
|
+
static fromSpecifier(specifier) {
|
|
74
|
+
return new Request(specifier);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** @type {string} */
|
|
78
|
+
#to;
|
|
79
|
+
|
|
80
|
+
/** @type {Request | undefined} */
|
|
81
|
+
#from;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* @private
|
|
85
|
+
* @param {string} specifier
|
|
86
|
+
*/
|
|
87
|
+
constructor(specifier) {
|
|
88
|
+
const removedPrefix = specifier.replace(unzippedPrefix, '');
|
|
89
|
+
const [full, query] = removedPrefix.split('?');
|
|
90
|
+
|
|
91
|
+
this.original = specifier;
|
|
92
|
+
|
|
93
|
+
assert(`Invalid specifier: ${specifier}`, full);
|
|
94
|
+
|
|
95
|
+
if (full.startsWith('.') || full.startsWith('#')) {
|
|
96
|
+
if (!query) {
|
|
97
|
+
throw new Error(
|
|
98
|
+
`Missing query, ?from for specifier: ${specifier}. From is required for relative and subpath-imports.`
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* This will either be '.' or have the leading ./
|
|
105
|
+
*/
|
|
106
|
+
this.#to = full;
|
|
107
|
+
|
|
108
|
+
if (query) {
|
|
109
|
+
const search = new URLSearchParams(query);
|
|
110
|
+
const fromQp = search.get('from');
|
|
111
|
+
|
|
112
|
+
assert(`Missing query, ?from for specifier: ${specifier}`, fromQp);
|
|
113
|
+
|
|
114
|
+
const from = Request.fromRequestId(fromQp);
|
|
115
|
+
|
|
116
|
+
this.#from = from;
|
|
117
|
+
this.name = from.name;
|
|
118
|
+
this.version = from.version;
|
|
119
|
+
} else {
|
|
120
|
+
const parsed = parseSpecifier(full);
|
|
121
|
+
const { name, version = 'latest', path } = parsed;
|
|
122
|
+
|
|
123
|
+
this.name = name;
|
|
124
|
+
this.version = version.replace(/\.+$/, '');
|
|
125
|
+
this.#to = path;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
get to() {
|
|
130
|
+
return this.#to;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
get from() {
|
|
134
|
+
return this.#from;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
get key() {
|
|
138
|
+
return `__name__/${this.name}[AT:V]${this.version}/__to__/${this.to}`;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { expect as errorExpect, it } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { idForRequest, Request } from './request.js';
|
|
4
|
+
import { fromImports } from './resolve.js';
|
|
5
|
+
|
|
6
|
+
import type { UntarredPackage } from './types.js';
|
|
7
|
+
|
|
8
|
+
const expect = errorExpect.soft;
|
|
9
|
+
|
|
10
|
+
it('resolves subpath imports', () => {
|
|
11
|
+
const untarred = {
|
|
12
|
+
contents: {
|
|
13
|
+
'pkg/standalone.js': 'entry file',
|
|
14
|
+
'pkg/compiler.js': 'target file',
|
|
15
|
+
'pkg/compiler/example.js': 'target file',
|
|
16
|
+
},
|
|
17
|
+
manifest: {
|
|
18
|
+
exports: {
|
|
19
|
+
'.': {
|
|
20
|
+
browser: { default: './pkg/standalone.js' },
|
|
21
|
+
default: { default: './pkg/node.cjs' },
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
imports: {
|
|
25
|
+
'#compiler': './pkg/compiler.js',
|
|
26
|
+
'#compiler/*': './pkg/compiler/*.js',
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
const from = idForRequest({ to: 'content-tag' });
|
|
31
|
+
const request = Request.of({ to: '#compiler', from });
|
|
32
|
+
const answer = fromImports(untarred as unknown as UntarredPackage, request, undefined);
|
|
33
|
+
|
|
34
|
+
expect(answer?.inTarFile).toBe('pkg/compiler.js');
|
|
35
|
+
});
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { expect as errorExpect, it } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { idForRequest, Request } from './request.js';
|
|
4
|
+
import { fromInternalImport } from './resolve.js';
|
|
5
|
+
|
|
6
|
+
import type { UntarredPackage } from './types.js';
|
|
7
|
+
|
|
8
|
+
const expect = errorExpect.soft;
|
|
9
|
+
|
|
10
|
+
it('resolves a private file (content-tag)', () => {
|
|
11
|
+
const untarred = {
|
|
12
|
+
contents: {
|
|
13
|
+
'pkg/standalone.js': 'entry file',
|
|
14
|
+
'pkg/standalone/content_tag.js': 'target file',
|
|
15
|
+
},
|
|
16
|
+
manifest: {
|
|
17
|
+
exports: {
|
|
18
|
+
'.': {
|
|
19
|
+
browser: { default: './pkg/standalone.js' },
|
|
20
|
+
default: { default: './pkg/node.cjs' },
|
|
21
|
+
},
|
|
22
|
+
'./standalone': {
|
|
23
|
+
import: { default: './pkg/standalone.js' },
|
|
24
|
+
require: { default: './pkg/stubs/require.cjs' },
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const from = idForRequest({ to: 'content-tag' });
|
|
31
|
+
const request = Request.of({ to: './standalone/content_tag.js', from });
|
|
32
|
+
const answer = fromInternalImport(untarred as unknown as UntarredPackage, request, undefined);
|
|
33
|
+
|
|
34
|
+
expect(answer?.inTarFile).toBe('pkg/standalone/content_tag.js');
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('resolves a private file (rehype-raw)', () => {
|
|
38
|
+
const untarred = {
|
|
39
|
+
contents: {
|
|
40
|
+
'pkg/index.js': 'entry file',
|
|
41
|
+
'pkg/lib/index.js': 'target file',
|
|
42
|
+
},
|
|
43
|
+
manifest: {
|
|
44
|
+
exports: './index.js',
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
const from = idForRequest({ to: 'rehype-raw' });
|
|
48
|
+
const request = Request.of({ to: './lib/index.js', from });
|
|
49
|
+
const answer = fromInternalImport(untarred as unknown as UntarredPackage, request, undefined);
|
|
50
|
+
|
|
51
|
+
expect(answer?.inTarFile).toBe('pkg/lib/index.js');
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('resolves the entrypoint (unist-util-visit)', () => {
|
|
55
|
+
const untarred = {
|
|
56
|
+
contents: {
|
|
57
|
+
'index.js': 'contents',
|
|
58
|
+
'lib/index.js': 'contents',
|
|
59
|
+
},
|
|
60
|
+
manifest: {
|
|
61
|
+
exports: './index.js',
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
const from = idForRequest({ to: 'unist-util-visit' });
|
|
65
|
+
const request = Request.of({ to: './lib/index.js', from });
|
|
66
|
+
const answer = fromInternalImport(untarred as unknown as UntarredPackage, request, undefined);
|
|
67
|
+
|
|
68
|
+
expect(answer?.inTarFile).toBe('lib/index.js');
|
|
69
|
+
});
|