tjs-lang 0.5.0 → 0.5.1
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/demo/src/imports.test.ts +22 -12
- package/demo/src/imports.ts +12 -16
- package/package.json +1 -1
package/demo/src/imports.test.ts
CHANGED
|
@@ -97,38 +97,44 @@ describe('extractImports', () => {
|
|
|
97
97
|
describe('getCDNUrl', () => {
|
|
98
98
|
it('should generate URL for simple package', () => {
|
|
99
99
|
expect(getCDNUrl('some-unknown-package')).toBe(
|
|
100
|
-
'https://
|
|
100
|
+
'https://cdn.jsdelivr.net/npm/some-unknown-package'
|
|
101
101
|
)
|
|
102
102
|
})
|
|
103
103
|
|
|
104
104
|
it('should use pinned version and path for known packages', () => {
|
|
105
105
|
// tosijs has pinned version and path
|
|
106
106
|
expect(getCDNUrl('tosijs')).toBe(
|
|
107
|
-
'https://
|
|
107
|
+
'https://cdn.jsdelivr.net/npm/tosijs@1.2.0/dist/module.js'
|
|
108
108
|
)
|
|
109
109
|
// date-fns has pinned version but no path
|
|
110
|
-
expect(getCDNUrl('date-fns')).toBe(
|
|
110
|
+
expect(getCDNUrl('date-fns')).toBe(
|
|
111
|
+
'https://cdn.jsdelivr.net/npm/date-fns@3.6.0'
|
|
112
|
+
)
|
|
111
113
|
})
|
|
112
114
|
|
|
113
115
|
it('should handle subpath imports with pinned version', () => {
|
|
114
116
|
expect(getCDNUrl('lodash-es/debounce')).toBe(
|
|
115
|
-
'https://
|
|
117
|
+
'https://cdn.jsdelivr.net/npm/lodash-es@4.17.21/debounce'
|
|
116
118
|
)
|
|
117
119
|
})
|
|
118
120
|
|
|
119
121
|
it('should handle scoped packages', () => {
|
|
120
|
-
expect(getCDNUrl('@scope/package')).toBe(
|
|
122
|
+
expect(getCDNUrl('@scope/package')).toBe(
|
|
123
|
+
'https://cdn.jsdelivr.net/npm/@scope/package'
|
|
124
|
+
)
|
|
121
125
|
})
|
|
122
126
|
|
|
123
127
|
it('should handle scoped packages with subpaths', () => {
|
|
124
128
|
expect(getCDNUrl('@scope/package/utils')).toBe(
|
|
125
|
-
'https://
|
|
129
|
+
'https://cdn.jsdelivr.net/npm/@scope/package/utils'
|
|
126
130
|
)
|
|
127
131
|
})
|
|
128
132
|
|
|
129
133
|
it('should handle packages with pinned version but no path', () => {
|
|
130
134
|
// lodash-es is pinned but has no explicit path
|
|
131
|
-
expect(getCDNUrl('lodash-es')).toBe(
|
|
135
|
+
expect(getCDNUrl('lodash-es')).toBe(
|
|
136
|
+
'https://cdn.jsdelivr.net/npm/lodash-es@4.17.21'
|
|
137
|
+
)
|
|
132
138
|
})
|
|
133
139
|
})
|
|
134
140
|
|
|
@@ -137,8 +143,8 @@ describe('generateImportMap', () => {
|
|
|
137
143
|
const result = generateImportMap(['tosijs', 'date-fns'])
|
|
138
144
|
expect(result).toEqual({
|
|
139
145
|
imports: {
|
|
140
|
-
tosijs: 'https://
|
|
141
|
-
'date-fns': 'https://
|
|
146
|
+
tosijs: 'https://cdn.jsdelivr.net/npm/tosijs@1.2.0/dist/module.js',
|
|
147
|
+
'date-fns': 'https://cdn.jsdelivr.net/npm/date-fns@3.6.0',
|
|
142
148
|
},
|
|
143
149
|
})
|
|
144
150
|
})
|
|
@@ -150,7 +156,7 @@ describe('generateImportMap', () => {
|
|
|
150
156
|
it('should handle subpath imports', () => {
|
|
151
157
|
const result = generateImportMap(['lodash-es/debounce'])
|
|
152
158
|
expect(result.imports['lodash-es/debounce']).toBe(
|
|
153
|
-
'https://
|
|
159
|
+
'https://cdn.jsdelivr.net/npm/lodash-es@4.17.21/debounce'
|
|
154
160
|
)
|
|
155
161
|
})
|
|
156
162
|
})
|
|
@@ -158,14 +164,18 @@ describe('generateImportMap', () => {
|
|
|
158
164
|
describe('generateImportMapScript', () => {
|
|
159
165
|
it('should generate script tag with import map', () => {
|
|
160
166
|
const importMap = {
|
|
161
|
-
imports: {
|
|
167
|
+
imports: {
|
|
168
|
+
tosijs: 'https://cdn.jsdelivr.net/npm/tosijs@1.0.10/dist/module.js',
|
|
169
|
+
},
|
|
162
170
|
}
|
|
163
171
|
const script = generateImportMapScript(importMap)
|
|
164
172
|
|
|
165
173
|
expect(script).toContain('<script type="importmap">')
|
|
166
174
|
expect(script).toContain('</script>')
|
|
167
175
|
expect(script).toContain('"tosijs"')
|
|
168
|
-
expect(script).toContain(
|
|
176
|
+
expect(script).toContain(
|
|
177
|
+
'https://cdn.jsdelivr.net/npm/tosijs@1.0.10/dist/module.js'
|
|
178
|
+
)
|
|
169
179
|
})
|
|
170
180
|
})
|
|
171
181
|
|
package/demo/src/imports.ts
CHANGED
|
@@ -2,33 +2,34 @@
|
|
|
2
2
|
* Playground Import Resolver
|
|
3
3
|
*
|
|
4
4
|
* Resolves and fetches external modules for the TJS playground.
|
|
5
|
-
* Uses
|
|
6
|
-
*
|
|
7
|
-
* Note: unpkg serves files directly from npm, unlike esm.sh which
|
|
8
|
-
* converts CJS to ESM. For packages without proper ESM exports,
|
|
9
|
-
* you need to specify the exact path to the ESM bundle.
|
|
5
|
+
* Uses cdn.jsdelivr.net for npm packages.
|
|
10
6
|
*
|
|
11
7
|
* Features:
|
|
12
8
|
* - Detects import statements in code
|
|
13
|
-
* - Fetches modules from
|
|
9
|
+
* - Fetches modules from jsdelivr with pinned versions
|
|
14
10
|
* - Caches fetched modules in memory
|
|
15
11
|
* - Returns import map for browser
|
|
16
12
|
*/
|
|
17
13
|
|
|
18
|
-
// CDN base URL -
|
|
19
|
-
const CDN_BASE = 'https://
|
|
14
|
+
// CDN base URL - jsdelivr serves npm packages with proper ESM support
|
|
15
|
+
const CDN_BASE = 'https://cdn.jsdelivr.net/npm'
|
|
20
16
|
|
|
21
17
|
// In-memory cache for fetched module URLs
|
|
22
18
|
const moduleCache = new Map<string, string>()
|
|
23
19
|
|
|
24
|
-
// Common packages
|
|
25
|
-
// unpkg serves files directly, so we need explicit paths to ESM bundles
|
|
20
|
+
// Common packages with pinned versions and ESM paths
|
|
26
21
|
// Packages with proper "exports" or "module" fields in package.json
|
|
27
22
|
// may work without explicit paths, but it's safer to specify them
|
|
28
23
|
const PINNED_PACKAGES: Record<
|
|
29
24
|
string,
|
|
30
25
|
{ version: string; path?: string; cdn?: string }
|
|
31
26
|
> = {
|
|
27
|
+
// tjs-lang itself (used by demos like Universal Endpoint)
|
|
28
|
+
'tjs-lang': {
|
|
29
|
+
version: '0.5.1',
|
|
30
|
+
cdn: 'https://cdn.jsdelivr.net/npm/tjs-lang@0.5.1/dist/index.js',
|
|
31
|
+
},
|
|
32
|
+
|
|
32
33
|
// tosijs ecosystem
|
|
33
34
|
tosijs: { version: '1.2.0', path: '/dist/module.js' },
|
|
34
35
|
'tosijs-ui': { version: '1.2.0', path: '/dist/index.js' },
|
|
@@ -118,10 +119,6 @@ function parseSpecifier(specifier: string): { name: string; subpath: string } {
|
|
|
118
119
|
|
|
119
120
|
/**
|
|
120
121
|
* Get CDN URL for a package specifier
|
|
121
|
-
*
|
|
122
|
-
* unpkg serves files directly from npm packages. For ESM packages,
|
|
123
|
-
* we often need to specify the exact path to the ESM bundle since
|
|
124
|
-
* unpkg doesn't do automatic ESM conversion like esm.sh.
|
|
125
122
|
*/
|
|
126
123
|
export function getCDNUrl(specifier: string): string {
|
|
127
124
|
const { name, subpath } = parseSpecifier(specifier)
|
|
@@ -145,8 +142,7 @@ export function getCDNUrl(specifier: string): string {
|
|
|
145
142
|
return `${CDN_BASE}/${name}@${pinned.version}${path}`
|
|
146
143
|
}
|
|
147
144
|
|
|
148
|
-
// For unknown packages, try
|
|
149
|
-
// This may not work for all packages if they don't have proper ESM exports
|
|
145
|
+
// For unknown packages, try jsdelivr's default resolution
|
|
150
146
|
return `${CDN_BASE}/${name}${subpath}`
|
|
151
147
|
}
|
|
152
148
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tjs-lang",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "Type-safe JavaScript dialect with runtime validation, sandboxed VM execution, and AI agent orchestration. Transpiles TypeScript to validated JS with fuel-metered execution for untrusted code.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|