Skip to content

Commit

Permalink
style: format code
Browse files Browse the repository at this point in the history
  • Loading branch information
SASUKE40 committed Apr 13, 2020
1 parent a972e3b commit 2c4a6c2
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 51 deletions.
2 changes: 1 addition & 1 deletion test/fixtures/sass-data-prepend/index.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
import './style.scss';
import './style.scss'
32 changes: 17 additions & 15 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,35 +56,36 @@ function snapshot({
options = {}
}) {
test(title, async () => {
let res
let result
try {
res = await write({
result = await write({
input,
outDir,
options
})
} catch (err) {
const frame = err.codeFrame || err.snippet
} catch (error) {
const frame = error.codeFrame || error.snippet
if (frame) {
throw new Error(frame + err.message)
throw new Error(frame + error.message)
}
throw err

throw error
}

expect(await res.jsCode()).toMatchSnapshot('js code')
expect(await result.jsCode()).toMatchSnapshot('js code')

if (options.extract) {
expect(await res.hasCssFile()).toBe(true)
expect(await res.cssCode()).toMatchSnapshot('css code')
expect(await result.hasCssFile()).toBe(true)
expect(await result.cssCode()).toMatchSnapshot('css code')
}

const sourceMap = options && options.sourceMap
if (sourceMap === 'inline') {
expect(await res.hasCssMapFile()).toBe(false)
expect(await result.hasCssMapFile()).toBe(false)
} else if (sourceMap === true) {
expect(await res.hasCssMapFile()).toBe(Boolean(options.extract))
expect(await result.hasCssMapFile()).toBe(Boolean(options.extract))
if (options.extract) {
expect(await res.cssMap()).toMatchSnapshot('css map')
expect(await result.cssMap()).toMatchSnapshot('css map')
}
}
})
Expand Down Expand Up @@ -349,7 +350,7 @@ snapshotMany('sass', [
])

test('onExtract', async () => {
const res = await write({
const result = await write({
input: 'simple/index.js',
outDir: 'onExtract',
options: {
Expand All @@ -359,8 +360,8 @@ test('onExtract', async () => {
}
}
})
expect(await res.jsCode()).toMatchSnapshot()
expect(await res.hasCssFile()).toBe(false)
expect(await result.jsCode()).toMatchSnapshot()
expect(await result.hasCssFile()).toBe(false)
})

test('augmentChunkHash', async () => {
Expand All @@ -381,6 +382,7 @@ test('augmentChunkHash', async () => {
})
outputFiles.push(output[0])
}

const [fooOne, fooTwo, barOne] = outputFiles

const fooHash = fooOne.fileName.split('.')[1]
Expand Down
75 changes: 40 additions & 35 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,49 @@
import { Plugin } from 'rollup'
import { CreateFilter } from 'rollup-pluginutils'

type FunctionType<T = any, U = any> = (...args: T[]) => U;
type FunctionType<T = any, U = any> = (...args: readonly T[]) => U;

type onExtract = (asset: {
code: any
map: any
codeFileName: string
mapFileName: string
}) => boolean
type onExtract = (asset: Readonly<{
code: any;
map: any;
codeFileName: string;
mapFileName: string;
}>) => boolean;

export type PostCSSPluginConf = {
inject?: boolean | { [key: string]: any } | ((cssVariableName: string, id: string) => string)
extract?: boolean | string
onExtract?: onExtract
modules?: boolean | { [key: string]: any }
extensions?: string[]
plugins?: any[]
autoModules?: boolean
namedExports?: boolean | ((id: string) => boolean)
minimize?: boolean | any
parser?: string | FunctionType
stringifier?: string | FunctionType
syntax?: string | FunctionType
exec?: boolean
config?: boolean | {
path: string
ctx: any
};
to?: string
name?: any[] | any[][]
loaders?: any[]
onImport?: (id: string) => void
use?: string[] | { [key in 'sass' | 'stylus' | 'less']: any }
/**
inject?:
| boolean
| { [key: string]: any }
| ((cssVariableName: string, id: string) => string);
extract?: boolean | string;
onExtract?: onExtract;
modules?: boolean | { [key: string]: any };
extensions?: string[];
plugins?: any[];
autoModules?: boolean;
namedExports?: boolean | ((id: string) => boolean);
minimize?: boolean | any;
parser?: string | FunctionType;
stringifier?: string | FunctionType;
syntax?: string | FunctionType;
exec?: boolean;
config?:
| boolean
| {
path: string;
ctx: any;
};
to?: string;
name?: any[] | any[][];
loaders?: any[];
onImport?: (id: string) => void;
use?: string[] | { [key in 'sass' | 'stylus' | 'less']: any };
/**
* @default: false
**/
sourceMap?: boolean | 'inline'
include?: Parameters<CreateFilter>[0]
exclude?: Parameters<CreateFilter>[1]
}
sourceMap?: boolean | 'inline';
include?: Parameters<CreateFilter>[0];
exclude?: Parameters<CreateFilter>[1];
};

export default function (options: PostCSSPluginConf): Plugin
export default function (options: Readonly<PostCSSPluginConf>): Plugin

0 comments on commit 2c4a6c2

Please sign in to comment.