Skip to content

Commit

Permalink
chore: test apple-arm64 arch compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
ErKeLost committed Jan 17, 2024
1 parent 2bfeddf commit 1cd288f
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 68 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
}
},
"dependencies": {
"@fervid/napi": "^0.2.0",
"@fervid/napi": "^0.2.1",
"debug": "^4.3.4",
"unplugin": "~1.6.0",
"vite": "^5.0.11",
Expand Down
46 changes: 33 additions & 13 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 4 additions & 6 deletions src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ import type {
// eslint-disable-next-line import/no-duplicates
import type * as _compiler from 'vue/compiler-sfc'

// import { compileSync } from '@fervid/napi'

export { parseVueRequest, type VueQuery } from './utils/query'

export interface Options {
Expand Down Expand Up @@ -137,10 +135,10 @@ function resolveOptions(rawOptions: Options): ResolvedOptions {
export const plugin = createUnplugin<Options | undefined, false>(
(rawOptions = {}, meta) => {
const options = shallowRef(resolveOptions(rawOptions))
// const compiler = new Compiler({
// isProduction: true
// })
// console.log(Compiler);
const compiler = new Compiler({
isProduction: true
})
console.log(compiler.compileAsync);

const filter = computed(() =>
createFilter(options.value.include, options.value.exclude),
Expand Down
96 changes: 48 additions & 48 deletions src/core/test-stable-compiler.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { createUnplugin } from "unplugin";
import { compileSync } from "@fervid/napi";
import VirtualModulesPlugin from "webpack-virtual-modules";

const plugin = createUnplugin(() => {
// const isProd = "production";
const isProd = true;
const hmr = false
const shouldAddHmr = hmr;
// const bundler = meta.framework;
const bundler = 'webpack'
import { createUnplugin } from 'unplugin'
import { Compiler } from '@fervid/napi'
import VirtualModulesPlugin from 'webpack-virtual-modules'

const unplugin = createUnplugin(({ mode = 'production', hmr = false }, meta) => {

Check failure on line 5 in src/core/test-stable-compiler.ts

View workflow job for this annotation

GitHub Actions / lint

Argument of type '({ mode, hmr }: { mode?: string | undefined; hmr?: boolean | undefined; }, meta: UnpluginContextMeta) => { name: string; transformInclude(id: string): boolean; transform(this: UnpluginBuildContext & UnpluginContext, code: string, id: string): string; webpack(compiler: Compiler): void; }' is not assignable to parameter of type 'UnpluginFactory<unknown, boolean>'.
const isProduction = mode === 'production'
const shouldAddHmr = hmr
const bundler = meta.framework

const compiler = new Compiler({
isProduction
})

/** @type {VirtualModulesPlugin | undefined} */
let vfs = undefined;
let vfs = undefined

Check failure on line 15 in src/core/test-stable-compiler.ts

View workflow job for this annotation

GitHub Actions / lint

Variable 'vfs' implicitly has type 'any' in some locations where its type cannot be determined.

/**
* Adds a file to Virtual File System.
Expand All @@ -20,58 +21,58 @@ const plugin = createUnplugin(() => {
* @param {string} content
*/
function addVirtualFile(id, content) {

Check failure on line 23 in src/core/test-stable-compiler.ts

View workflow job for this annotation

GitHub Actions / lint

Parameter 'id' implicitly has an 'any' type.

Check failure on line 23 in src/core/test-stable-compiler.ts

View workflow job for this annotation

GitHub Actions / lint

Parameter 'content' implicitly has an 'any' type.
if (bundler === "webpack" && vfs) {
vfs.writeModule(id, content);
if (bundler === 'webpack' && vfs) {

Check failure on line 24 in src/core/test-stable-compiler.ts

View workflow job for this annotation

GitHub Actions / lint

Variable 'vfs' implicitly has an 'any' type.
vfs.writeModule(id, content)
}
}

return {
name: "unplugin-fervid",
name: 'unplugin-fervid',

transformInclude(id) {
return id.endsWith(".vue");
return id.endsWith('.vue')
},

transform(code, id) {
const compileResult = compileSync(code, { isProd });
const compileResult = compiler.compileSync(code)

/** @type {string[]} */
const assetImports = [];
const assetImports = []
for (const style of compileResult.styles) {
const idx = assetImports.length;
const idx = assetImports.length

Check failure on line 42 in src/core/test-stable-compiler.ts

View workflow job for this annotation

GitHub Actions / lint

'idx' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.

// e.g. `input.vue` -> `input.vue.2.css`
const newId = `${id}.${idx}.${style.lang}`;
const imported = `import '${newId}'`;
assetImports.push(imported);
addVirtualFile(newId, style.code);
const newId = `${id}.${idx}.${style.lang}`

Check failure on line 45 in src/core/test-stable-compiler.ts

View workflow job for this annotation

GitHub Actions / lint

'newId' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.
const imported = `import '${newId}'`

Check failure on line 46 in src/core/test-stable-compiler.ts

View workflow job for this annotation

GitHub Actions / lint

'imported' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.
assetImports.push(imported)
addVirtualFile(newId, style.code)
}

const base = assetImports.join("\n") + "\n" + compileResult.code;
const base = assetImports.join('\n') + '\n' + compileResult.code
if (!shouldAddHmr) {
return base;
return base
}

const hmr = bundler === "webpack" ? webpackHmr(id) : viteHmr(id);
const hmr = bundler === 'webpack'
? webpackHmr(id)
: viteHmr(id)

return base + hmr;
return base + hmr
},

webpack(compiler) {
// Find a VirtualModulesPlugin or create a new one
vfs = compiler.options.plugins.find(
(p) => p instanceof VirtualModulesPlugin
);
vfs = compiler.options.plugins.find(p => p instanceof VirtualModulesPlugin)
if (!vfs) {
vfs = new VirtualModulesPlugin();
compiler.options.plugins.push(vfs);
vfs = new VirtualModulesPlugin()
compiler.options.plugins.push(vfs)
}
},
};
});
}
}
})

/** @param {string} id */
function webpackHmr(id) {
function webpackHmr (id) {

Check failure on line 75 in src/core/test-stable-compiler.ts

View workflow job for this annotation

GitHub Actions / lint

Parameter 'id' implicitly has an 'any' type.
return `
if (import.meta.webpackHot) {
__WEBPACK_DEFAULT_EXPORT__.__hmrId = '${id}'
Expand All @@ -80,15 +81,15 @@ if (import.meta.webpackHot) {
if (!api.createRecord('${id}', __WEBPACK_DEFAULT_EXPORT__)) {
api.reload('${id}', __WEBPACK_DEFAULT_EXPORT__)
}
}`;
// module.hot.accept('${id}', () => {
// api.rerender('${id}', __WEBPACK_DEFAULT_EXPORT__.render)
// })
}`
// module.hot.accept('${id}', () => {
// api.rerender('${id}', __WEBPACK_DEFAULT_EXPORT__.render)
// })
}

// TODO This is untested
/** @param {string} id */
function viteHmr(id) {
function viteHmr (id) {

Check failure on line 92 in src/core/test-stable-compiler.ts

View workflow job for this annotation

GitHub Actions / lint

Parameter 'id' implicitly has an 'any' type.
return `
if (import.meta.hot) {
import.meta.hot.accept((newModule) => {
Expand All @@ -101,12 +102,11 @@ if (import.meta.hot) {
api.reload('${id}', newModule)
}
})
}`;
}`
}

export const vitePlugin = plugin.vite;
export const rollupPlugin = plugin.rollup;
export const webpackPlugin = plugin.webpack;
export const rspackPlugin = plugin.rspack;
export const esbuildPlugin = plugin.esbuild;
export { plugin };
export const vitePlugin = unplugin.vite
export const rollupPlugin = unplugin.rollup
export const webpackPlugin = unplugin.webpack
export const rspackPlugin = unplugin.rspack
export const esbuildPlugin = unplugin.esbuild

0 comments on commit 1cd288f

Please sign in to comment.