Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use esm.sh as default CDN #488

Merged
merged 2 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/livecodes/compiler/__tests__/import-map.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ describe('Import map', () => {
`;

const importMap = {
'@codemirror/basic-setup': 'https://jspm.dev/@codemirror/basic-setup',
'@codemirror/basic-setup': 'https://esm.sh/@codemirror/basic-setup',
lodash: 'https://unpkg.com/lodash',
mylib: 'https://someurl/path/module',
similar2: 'https://jspm.dev/similar2',
similar2: 'https://esm.sh/similar2',
};

const map = createImportMap(code, config);
Expand Down Expand Up @@ -60,7 +60,7 @@ describe('Import map', () => {
`;

const expectedCode = `
import { EditorState, EditorView, basicSetup } from 'https://jspm.dev/@codemirror/basic-setup';
import { EditorState, EditorView, basicSetup } from 'https://esm.sh/@codemirror/basic-setup';
import fp from "https://unpkg.com/lodash/fp.js";
import { html } from 'http://localhost/@codemirror/lang-html';
import { flatten } from 'https://cdn.jsdelivr.net/gh/remeda/remeda@master/src/flatten.js';
Expand Down
8 changes: 4 additions & 4 deletions src/livecodes/services/__tests__/modulesService.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ describe('modulesService', () => {
test('CDN urls', () => {
const url = modulesService.getModuleUrl;

expect(url('uuid')).toEqual('https://jspm.dev/uuid');
expect(url('uuid')).toEqual('https://esm.sh/uuid');

expect(url('[email protected]')).toEqual('https://jspm.dev/[email protected]');
expect(url('[email protected]')).toEqual('https://esm.sh/[email protected]');

expect(url('[email protected]/sub/directory/file.js')).toEqual(
'https://jspm.dev/[email protected]/sub/directory/file.js',
'https://esm.sh/[email protected]/sub/directory/file.js',
);

expect(url('jspm:uuid')).toEqual('https://jspm.dev/uuid');

expect(url('npm:uuid')).toEqual('https://jspm.dev/uuid');
expect(url('npm:uuid')).toEqual('https://esm.sh/uuid');

expect(url('skypack:uuid')).toEqual('https://cdn.skypack.dev/uuid');

Expand Down
12 changes: 5 additions & 7 deletions src/livecodes/services/modules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import type { CDN } from '../models';

declare const globalThis: { appCDN: CDN };

const moduleCDNs: CDN[] = ['jspm', 'esm.sh', 'skypack'];
const moduleCDNs: CDN[] = ['esm.sh', 'skypack', 'jspm'];
const npmCDNs: CDN[] = ['unpkg', 'jsdelivr', 'fastly.jsdelivr'];
const ghCDNs: CDN[] = ['fastly.jsdelivr.gh', 'jsdelivr.gh', 'statically'];

export const modulesService = {
getModuleUrl: (
moduleName: string,
{ isModule = true, defaultCDN = 'jspm' }: { isModule?: boolean; defaultCDN?: CDN } = {},
{ isModule = true, defaultCDN = 'esm.sh' }: { isModule?: boolean; defaultCDN?: CDN } = {},
) => {
moduleName = moduleName.replace(/#nobundle/g, '');

Expand All @@ -18,9 +18,7 @@ export const modulesService = {
return moduleUrl;
}

return isModule
? 'https://jspm.dev/' + moduleName
: 'https://cdn.jsdelivr.net/npm/' + moduleName;
return isModule ? 'https://esm.sh/' + moduleName : 'https://cdn.jsdelivr.net/npm/' + moduleName;
},

getUrl: (path: string, cdn?: CDN) =>
Expand Down Expand Up @@ -76,9 +74,9 @@ const getCdnUrl = (modName: string, isModule: boolean, defaultCDN?: CDN) => {
const TEMPLATES: Array<[RegExp, string]> = [
[/^(jspm:)(.+)/i, 'https://jspm.dev/$2'],

[/^(npm:)(.+)/i, 'https://jspm.dev/$2'],
[/^(npm:)(.+)/i, 'https://esm.sh/$2'],

[/^(node:)(.+)/i, 'https://jspm.dev/$2'],
[/^(node:)(.+)/i, 'https://esm.sh/$2'],

[/^(skypack:)(.+)/i, 'https://cdn.skypack.dev/$2'],

Expand Down
4 changes: 3 additions & 1 deletion src/livecodes/templates/starter/preact-starter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ render(<App name="Preact" />, document.body);
stylesheets: [],
scripts: [],
cssPreset: '',
imports: {},
types: {},
customSettings: {
defaultCDN: 'jspm',
},
};
1 change: 1 addition & 0 deletions src/livecodes/toolspane/test-imports.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { chaiUrl, vendorsBaseUrl } from '../vendors';

export const testImports = {
react: 'https://esm.sh/react?dev',
'@testing-library/dom': vendorsBaseUrl + '@testing-library/dom.js',
'@testing-library/jest-dom': vendorsBaseUrl + '@testing-library/jest-dom.js',
'@testing-library/react': vendorsBaseUrl + '@testing-library/react.js',
Expand Down
Loading