Skip to content
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
35 changes: 29 additions & 6 deletions packages/docs/src/components/repl/monaco.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { Diagnostic } from '@builder.io/qwik/optimizer';
import type MonacoTypes from 'monaco-editor';
import type { EditorProps, EditorStore } from './editor';
import type { ReplStore } from './types';
import { QWIK_REPL_DEPS_CACHE } from './worker/repl-constants';

export const initMonacoEditor = async (
containerElm: any,
Expand Down Expand Up @@ -220,8 +221,16 @@ const loadDeps = async (qwikVersion: string) => {
pkgPath: '/server.d.ts',
path: '/node_modules/@types/builder.io__qwik/server.d.ts',
},
{
pkgName: '@builder.io/qwik',
pkgVersion: qwikVersion,
pkgPath: '/build/index.d.ts',
path: '/node_modules/@types/builder.io__qwik/build/index.d.ts',
},
];

const cache = await caches.open(QWIK_REPL_DEPS_CACHE);

await Promise.all(
deps.map(async (dep) => {
let storedDep = monacoCtx.deps.find(
Expand All @@ -238,12 +247,9 @@ const loadDeps = async (qwikVersion: string) => {
monacoCtx.deps.push(storedDep);

storedDep.promise = new Promise<void>((resolve, reject) => {
const url = getCdnUrl(dep.pkgName, dep.pkgVersion, dep.pkgPath);
fetch(url).then((rsp) => {
rsp.text().then((code) => {
storedDep!.code = code;
resolve();
}, reject);
fetchDep(cache, dep).then((code) => {
storedDep!.code = code;
resolve();
}, reject);
});
}
Expand All @@ -254,6 +260,23 @@ const loadDeps = async (qwikVersion: string) => {
return monacoCtx.deps;
};

const fetchDep = async (cache: Cache, dep: NodeModuleDep) => {
const url = getCdnUrl(dep.pkgName, dep.pkgVersion, dep.pkgPath);
const req = new Request(url);
const cachedRes = await cache.match(req);
if (cachedRes) {
return cachedRes.clone().text();
}
const fetchRes = await fetch(req);
if (fetchRes.ok) {
if (!req.url.includes('localhost')) {
await cache.put(req, fetchRes.clone());
}
return fetchRes.clone().text();
}
throw new Error(`Unable to fetch: ${url}`);
};

const getMonaco = async (): Promise<Monaco> => {
if (!monacoCtx.loader) {
// lazy-load the monaco AMD script ol' school
Expand Down
6 changes: 3 additions & 3 deletions packages/docs/src/components/repl/worker/repl-constants.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export const QWIK_PKG_NAME = '@builder.io/qwik';
export const ROLLUP_VERSION = '2.75.4';
export const PRETTIER_VERSION = '2.6.2';
export const TERSER_VERSION = '5.14.0';
export const ROLLUP_VERSION = '2.75.6';
export const PRETTIER_VERSION = '2.7.1';
export const TERSER_VERSION = '5.14.1';

export const QWIK_REPL_DEPS_CACHE = 'QwikReplDeps';
export const QWIK_REPL_RESULT_CACHE = 'QwikReplResults';
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ export const depResponse = async (
}
const fetchRes = await fetch(req);
if (fetchRes.ok) {
await cache.put(req, fetchRes.clone());
if (!req.url.includes('localhost')) {
await cache.put(req, fetchRes.clone());
}
return fetchRes;
}
};
Expand Down
6 changes: 3 additions & 3 deletions packages/qwik/src/optimizer/src/plugins/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,15 +275,15 @@ export function createPlugin(optimizerOptions: OptimizerOptions = {}) {
if (id === QWIK_BUILD_ID) {
log(`resolveId()`, 'Resolved', QWIK_BUILD_ID);
return {
id: path.resolve(opts.rootDir, QWIK_BUILD_ID),
id: normalizePath(path.resolve(opts.rootDir, QWIK_BUILD_ID)),
moduleSideEffects: false,
};
}

if (id.endsWith(QWIK_CLIENT_MANIFEST_ID)) {
log(`resolveId()`, 'Resolved', QWIK_CLIENT_MANIFEST_ID);
return {
id: path.resolve(opts.input[0], QWIK_CLIENT_MANIFEST_ID),
id: normalizePath(path.resolve(opts.input[0], QWIK_CLIENT_MANIFEST_ID)),
moduleSideEffects: false,
};
}
Expand Down Expand Up @@ -322,7 +322,7 @@ export function createPlugin(optimizerOptions: OptimizerOptions = {}) {
};

const load = async (_ctx: any, id: string, loadOpts: { ssr?: boolean } = {}) => {
if (id === QWIK_BUILD_ID) {
if (id.endsWith(QWIK_BUILD_ID)) {
log(`load()`, QWIK_BUILD_ID, opts.buildMode);
return {
moduleSideEffects: false,
Expand Down
3 changes: 2 additions & 1 deletion packages/qwik/src/optimizer/src/plugins/vite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
QWIK_JSX_RUNTIME_ID,
Q_MANIFEST_FILENAME,
QWIK_CLIENT_MANIFEST_ID,
QWIK_BUILD_ID,
} from './plugin';
import { createRollupError, normalizeRollupOutputOptions } from './rollup';
import { QWIK_LOADER_DEFAULT_DEBUG, QWIK_LOADER_DEFAULT_MINIFIED } from '../scripts';
Expand Down Expand Up @@ -135,7 +136,7 @@ export function qwikVite(qwikViteOpts: QwikVitePluginOptions = {}): any {
esbuild: { include: /\.js$/ },
optimizeDeps: {
include: [QWIK_CORE_ID, QWIK_JSX_RUNTIME_ID],
exclude: ['@vite/client', '@vite/env'],
exclude: ['@vite/client', '@vite/env', QWIK_BUILD_ID, QWIK_CLIENT_MANIFEST_ID],
},
build: {
outDir: opts.outDir,
Expand Down