Skip to content
Closed
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
28 changes: 14 additions & 14 deletions demos/turbopack-next15/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@
"lint": "next lint"
},
"dependencies": {
"react": "19.1.0",
"react-dom": "19.1.0",
"next": "15.4.4"
"next": "15.5.2",
"react": "19.1.1",
"react-dom": "19.1.1"
},
"devDependencies": {
"typescript": "^5",
"@types/node": "^20",
"@types/react": "^19",
"@types/react-dom": "^19",
"@tailwindcss/postcss": "^4",
"tailwindcss": "^4",
"eslint": "^9",
"eslint-config-next": "15.4.4",
"@eslint/eslintrc": "^3",
"@eslint/eslintrc": "^3.3.1",
"@mdx-js/loader": "^3.1.1",
"@next/mdx": "15.5.2",
"@tailwindcss/postcss": "^4.1.13",
"@types/node": "^24.3.1",
"@types/react": "^19.1.12",
"@types/react-dom": "^19.1.9",
"code-inspector-plugin": "workspace:^",
"@next/mdx": "15.4.4",
"@mdx-js/loader": "^3.1.0"
"eslint": "^9.34.0",
"eslint-config-next": "15.5.2",
"tailwindcss": "^4.1.13",
"typescript": "^5.9.2"
}
}
4 changes: 4 additions & 0 deletions demos/turbopack-next15/src/middleware.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export function middleware() {
// This empty middleware demonstrates that code-inspector
// works correctly with Turbopack when middleware.ts is present
}
1 change: 1 addition & 0 deletions packages/code-inspector-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"keywords": [
"webpack",
"vite",
"turbopack",
"plugin",
"vue",
"vscode",
Expand Down
5 changes: 3 additions & 2 deletions packages/turbopack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"types": "./types/index.d.ts",
"default": "./dist/index.js"
}
}
},
"./dist/turbopack-loader.js": "./dist/turbopack-loader.js"
},
"keywords": [
"turbopack",
Expand All @@ -47,7 +48,7 @@
},
"scripts": {
"clear": "rimraf ./dist && rimraf ./types",
"build": "pnpm clear && tsc && vite build",
"build": "pnpm clear && tsc && vite build && cp src/turbopack-loader.js dist/",
"pub": "pnpm publish",
"pub:beta": "pnpm publish --tag beta"
}
Expand Down
50 changes: 15 additions & 35 deletions packages/turbopack/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { CodeOptions, RecordInfo, isDev } from '@code-inspector/core';
import path from 'path';
import { fileURLToPath } from 'url';
import {
CodeOptions,
RecordInfo,
isDev
} from '@code-inspector/core';

interface Options extends CodeOptions {
close?: boolean;
Expand All @@ -23,38 +25,16 @@ export function TurbopackCodeInspectorPlugin(
output: options.output,
};

let WebpackEntry = null;
if (typeof require !== 'undefined' && typeof require.resolve === 'function') {
WebpackEntry = require.resolve('@code-inspector/webpack');
}
if (typeof import.meta.resolve === 'function') {
const dir = import.meta.resolve(
'@code-inspector/webpack'
) as unknown as string;
WebpackEntry = fileURLToPath(dir);
}
const WebpackDistDir = path.resolve(WebpackEntry, '..');

return {
'**/*.{jsx,tsx,js,ts,mjs,mts}': {
loaders: [
{
loader: `${WebpackDistDir}/loader.js`,
options: {
...options,
record,
},
...(options.enforcePre === false ? {} : { enforce: 'pre' }),
},
{
loader: `${WebpackDistDir}/inject-loader.js`,
options: {
...options,
record,
},
enforce: 'pre',
},
],
},
'**/*.{jsx,tsx}': {
loaders: [{
loader: '@code-inspector/turbopack/dist/turbopack-loader.js',
options: {
...options,
record,
inject: true,
}
}]
}
};
}
38 changes: 38 additions & 0 deletions packages/turbopack/src/turbopack-loader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const {
normalizePath,
getCodeWithWebComponent,
isExcludedFile,
transformCode,
isJsTypeFile,
} = require('@code-inspector/core');

module.exports = async function turbopackLoader(content) {
this.cacheable && this.cacheable(true);
const filePath = normalizePath(this.resourcePath);
const options = this.query;

if (isExcludedFile(filePath, options)) {
return content;
}

// start server and inject client code to entry file
content = await getCodeWithWebComponent({
options,
file: filePath,
code: content,
record: options.record,
});

// Transform JSX/TSX files to add data-inspector attributes
if (isJsTypeFile(filePath)) {
content = transformCode({
content,
filePath,
fileType: 'jsx',
escapeTags: options.escapeTags || [],
pathType: options.pathType,
});
}

return content;
};