Skip to content

Commit

Permalink
fix: deprecate sideEffects options
Browse files Browse the repository at this point in the history
1. always treat as sideEffects now

2. dont skip build when options is same as before
  • Loading branch information
hemengke1997 committed Oct 30, 2023
1 parent faabab8 commit 4caaa45
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
2 changes: 1 addition & 1 deletion playground/spa-file-mode/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function App() {

return (
<div className='App'>
<h3 id='temp'>以下都是 vite-plugin-public-typescript 插件编译后,通过 manifest.json 文件获取的</h3>
<h3 id='temp'>以下都是 vite-plugin-public-typescript 插件编译后生成的js文件</h3>
<div className={'manifest'}>{formatManifst()}</div>
<br />
{content}
Expand Down
2 changes: 1 addition & 1 deletion playground/spa/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function App() {

return (
<div className='App'>
<h3 id='temp'>以下都是 vite-plugin-public-typescript 插件编译后,通过 manifest.json 文件获取的</h3>
<h3 id='temp'>以下都是 vite-plugin-public-typescript 插件编译后生成的js文件</h3>
<div className={'manifest'}>{formatManifst()}</div>
<br />
{content}
Expand Down
13 changes: 12 additions & 1 deletion src/node/helper/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import createDebug from 'debug'
import fs from 'fs-extra'
import { createHash } from 'node:crypto'
import path from 'node:path'
import colors from 'picocolors'
import glob from 'tiny-glob'
import { type ResolvedConfig, createLogger, normalizePath } from 'vite'
import { type VPPTPluginOptions } from '..'
Expand All @@ -15,7 +16,7 @@ const debug = createDebug('vite-plugin-public-typescript:util ===> ')

type PartialExclude<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>

export type OptionsTypeWithDefault = PartialExclude<Required<VPPTPluginOptions>, 'base'>
export type OptionsTypeWithDefault = PartialExclude<Required<VPPTPluginOptions>, 'base' | 'sideEffects'>

export { pkgName }

Expand Down Expand Up @@ -178,6 +179,16 @@ export function validateOptions(options: OptionsTypeWithDefault) {
// remove last slash
options.inputDir = inputDir.replace(/\/$/, '')
}

if (options.sideEffects !== undefined) {
console.warn(
colors.yellow(
`${colors.bold('(warning!)')} [${pkgName}]: sideEffects option is ${colors.bold(
'deprecated',
)}, please remove it`,
),
)
}
}

// remove slash at the start and end of path
Expand Down
13 changes: 6 additions & 7 deletions src/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { reloadPage } from './helper/server'
import {
_isPublicTypescript,
type OptionsTypeWithDefault,
eq,
findAllOldJsFile,
isEmptyObject,
isManifestFile,
Expand Down Expand Up @@ -68,6 +67,7 @@ export interface VPPTPluginOptions {
* @description treat `input` as sideEffect or not
* @see https://esbuild.github.io/api/#tree-shaking-and-side-effects
* @default true
* @deprecated in v2.0.0. always treat as sideEffect now
*/
sideEffects?: boolean
/**
Expand Down Expand Up @@ -97,11 +97,10 @@ export const DEFAULT_OPTIONS: OptionsTypeWithDefault = {
inputDir: 'public-typescript',
manifestName: 'manifest',
outputDir: '/',
sideEffects: true,
cacheDir: 'node_modules/.vite-plugin-public-typescript',
}

let previousOpts: VPPTPluginOptions
// let previousOpts: VPPTPluginOptions

export default function publicTypescript(options: VPPTPluginOptions = {}) {
const opts = {
Expand Down Expand Up @@ -133,11 +132,11 @@ export default function publicTypescript(options: VPPTPluginOptions = {}) {
},
async buildStart() {
// skip server restart when options not changed
if (eq(previousOpts, opts)) {
return
}
// if (eq(previousOpts, opts)) {
// return
// }

previousOpts = opts
// previousOpts = opts

const manifestPath = manifestCache.manifestPath

Expand Down

0 comments on commit 4caaa45

Please sign in to comment.