Skip to content

Commit

Permalink
emergency temporary revert of solid-refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
ryansolid committed Feb 14, 2024
1 parent 0051fb0 commit 1552678
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 40 deletions.
5 changes: 5 additions & 0 deletions .changeset/five-mayflies-stare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'vite-plugin-solid': patch
---

emergency temporary revert of solid-refresh
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"@types/babel__core": "^7.20.4",
"babel-preset-solid": "^1.8.4",
"merge-anything": "^5.1.7",
"solid-refresh": "^0.7.4",
"solid-refresh": "^0.6.3",
"vitefu": "^0.2.5"
},
"devDependencies": {
Expand Down
9 changes: 5 additions & 4 deletions pnpm-lock.yaml

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

43 changes: 9 additions & 34 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import * as babel from '@babel/core';
// @ts-ignore
import solid from 'babel-preset-solid';
import { readFileSync } from 'fs';
import { mergeAndConcat } from 'merge-anything';
import { createRequire } from 'module';
import solidRefresh from 'solid-refresh/babel';
// TODO use proper path
import type { Options as RefreshOptions } from 'solid-refresh/babel';
import type { Alias, AliasOptions, FilterPattern, Plugin } from 'vite';
import { createFilter } from 'vite';
import type { Alias, AliasOptions, Plugin, FilterPattern } from 'vite';
import { crawlFrameworkPkgs } from 'vitefu';

const require = createRequire(import.meta.url);
Expand Down Expand Up @@ -54,7 +51,6 @@ export interface Options {
* This will inject HMR runtime in dev mode. Has no effect in prod. If
* set to `false`, it won't inject the runtime in dev.
*
* @deprecated use `refresh` instead
* @default true
*/
hot: boolean;
Expand Down Expand Up @@ -146,8 +142,6 @@ export interface Options {
*/
builtIns?: string[];
};

refresh: Omit<RefreshOptions & { disabled: boolean }, 'bundler' | 'fixRender'>;
}

function getExtension(filename: string): string {
Expand Down Expand Up @@ -194,7 +188,7 @@ export default function solidPlugin(options: Partial<Options> = {}): Plugin {
async config(userConfig, { command }) {
// We inject the dev mode only if the user explicitely wants it or if we are in dev (serve) mode
replaceDev = options.dev === true || (options.dev !== false && command === 'serve');
projectRoot = userConfig.root || projectRoot;
projectRoot = userConfig.root;

if (!userConfig.resolve) userConfig.resolve = {};
userConfig.resolve.alias = normalizeAliases(userConfig.resolve && userConfig.resolve.alias);
Expand Down Expand Up @@ -261,7 +255,7 @@ export default function solidPlugin(options: Partial<Options> = {}): Plugin {
},

configResolved(config) {
needHmr = config.command === 'serve' && config.mode !== 'production' && (options.hot !== false && !options.refresh?.disabled);
needHmr = config.command === 'serve' && config.mode !== 'production' && options.hot !== false;
},

resolveId(id) {
Expand Down Expand Up @@ -313,19 +307,7 @@ export default function solidPlugin(options: Partial<Options> = {}): Plugin {

return extensionOptions.typescript;
});
const plugins: NonNullable<NonNullable<babel.TransformOptions['parserOpts']>['plugins']> = [
'jsx',
// import { example } from 'example' with { example: true };
'importAttributes',
// () => throw example
'throwExpressions',
// You know what this is
'decorators',
// const { #example: example } = this;
'destructuringPrivate',
// using example = myExample()
'explicitResourceManagement',
];
const plugins: NonNullable<NonNullable<babel.TransformOptions['parserOpts']>['plugins']> = ['jsx']

if (shouldBeProcessedWithTypescript) {
plugins.push('typescript');
Expand All @@ -336,12 +318,7 @@ export default function solidPlugin(options: Partial<Options> = {}): Plugin {
filename: id,
sourceFileName: id,
presets: [[solid, { ...solidOptions, ...(options.solid || {}) }]],
plugins: needHmr && !isSsr && !inNodeModules ? [[solidRefresh, {
bundler: 'vite',
fixRender: true,
imports: options.refresh?.imports,
granular: options.refresh?.granular,
}]] : [],
plugins: needHmr && !isSsr && !inNodeModules ? [[solidRefresh, { bundler: 'vite' }]] : [],
ast: false,
sourceMaps: true,
configFile: false,
Expand All @@ -356,7 +333,7 @@ export default function solidPlugin(options: Partial<Options> = {}): Plugin {

if (options.babel) {
if (typeof options.babel === 'function') {
const babelOptions = options.babel(source, id, !!isSsr);
const babelOptions = options.babel(source, id, isSsr);
babelUserOptions = babelOptions instanceof Promise ? await babelOptions : babelOptions;
} else {
babelUserOptions = options.babel;
Expand All @@ -365,11 +342,9 @@ export default function solidPlugin(options: Partial<Options> = {}): Plugin {

const babelOptions = mergeAndConcat(babelUserOptions, opts) as babel.TransformOptions;

const result = await babel.transformAsync(source, babelOptions);
if (!result) {
return undefined;
}
return { code: result.code || '', map: result.map };
const { code, map } = await babel.transformAsync(source, babelOptions);

return { code, map };
},
};
}
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "node",
"strict": true,
"strict": false,
"declaration": true,
"noUnusedLocals": true,
"skipLibCheck": true,
Expand Down

0 comments on commit 1552678

Please sign in to comment.