Skip to content

Commit 756b9fd

Browse files
authored
Merge pull request #9 from vite-plugin/v1.4.3
V1.4.3
2 parents 372e72a + 3a099d2 commit 756b9fd

5 files changed

Lines changed: 81 additions & 60 deletions

File tree

CHANGELOG.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
## [2022-10-15] v1.4.1
1+
## [2024-01-08] v1.4.3
2+
3+
- bec3951 fix: update types
4+
- 372e72a Merge pull request #8 from CharleeWa/main
5+
- 7d008ef chore: Specify TypeScript declaration file
6+
- ef68f59 Merge pull request #6 from learnsomesome/patch-1
7+
- 4294887 Update README.md
8+
9+
## [2022-10-15] v1.4.2
210

311
- bc1935f v1.4.2
412
- babc0e1 chroe: comments

index.d.ts

Lines changed: 53 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,63 @@
11
declare module 'vite-plugin-optimizer' {
2-
function optimizer(entries: Entries, options?: OptimizerOptions): import('vite').Plugin;
3-
// https://www.typescriptlang.org/docs/handbook/declaration-files/templates/module-d-ts.html#default-exports
4-
export = optimizer;
5-
}
6-
7-
export interface OptimizerArgs {
8-
/** Generated file cache directory */
9-
dir: string;
10-
}
2+
export interface OptimizerArgs {
3+
/** Generated file cache directory */
4+
dir: string;
5+
}
116

12-
export interface ResultDescription {
13-
/**
14-
* This is consistent with the `alias` behavior.
15-
*
16-
* e.g.
17-
* `import fs from 'fs'`
18-
* or
19-
* `import fs from 'node:fs'`
20-
*
21-
* @example
22-
* {
23-
* // This means that both 'fs' and 'node:fs' are supported.
24-
* find: /^(node:)?fs$/,
25-
* replacement: '/project/node_modules/.vite-plugin-optimizer/fs.js',
26-
* }
27-
*/
28-
alias?: {
29-
find: string | RegExp;
7+
export interface ResultDescription {
308
/**
31-
* If not explicitly specified, will use the path to the generated file as the default.
9+
* This is consistent with the `alias` behavior.
10+
*
11+
* e.g.
12+
* `import fs from 'fs'`
13+
* or
14+
* `import fs from 'node:fs'`
15+
*
16+
* @example
17+
* {
18+
* // This means that both 'fs' and 'node:fs' are supported.
19+
* find: /^(node:)?fs$/,
20+
* replacement: '/project/node_modules/.vite-plugin-optimizer/fs.js',
21+
* }
3222
*/
33-
replacement?: string;
34-
};
35-
code?: string;
36-
}
23+
alias?: {
24+
find: string | RegExp;
25+
/**
26+
* If not explicitly specified, will use the path to the generated file as the default.
27+
*/
28+
replacement?: string;
29+
};
30+
code?: string;
31+
}
3732

38-
export interface Entries {
39-
[moduleId: string]:
40-
| string
41-
| ResultDescription
42-
| ((args: OptimizerArgs) => string | ResultDescription | Promise<string | ResultDescription | void> | void);
43-
}
33+
export interface Entries {
34+
[moduleId: string]:
35+
| string
36+
| ResultDescription
37+
| ((args: OptimizerArgs) => string | ResultDescription | Promise<string | ResultDescription | void> | void);
38+
}
4439

45-
export interface OptimizerOptions {
46-
/**
47-
* @default ".vite-plugin-optimizer"
48-
*/
49-
dir?: string;
50-
resolveId?: ((id: string) => string | Promise<string | void> | void);
51-
}
40+
export interface OptimizerOptions {
41+
/**
42+
* @default ".vite-plugin-optimizer"
43+
*/
44+
dir?: string;
45+
resolveId?: ((id: string) => string | Promise<string | void> | void);
46+
}
5247

53-
// --------- utils ---------
48+
// --------- utils ---------
49+
50+
export type GenerateRecord = {
51+
alias?: ResultDescription['alias'];
52+
module: string;
53+
// Absolute path of file
54+
filename: string;
55+
};
5456

55-
export type GenerateRecord = {
56-
alias?: ResultDescription['alias'];
57-
module: string;
58-
// Absolute path of file
59-
filename: string;
60-
};
57+
export interface GenerateModule {
58+
(entries: Entries, options?: OptimizerOptions): Promise<GenerateRecord[]>;
59+
}
6160

62-
export interface GenerateModule {
63-
(entries: Entries, options?: OptimizerOptions): Promise<GenerateRecord[]>;
61+
const optimizer: ((entries: Entries, options?: OptimizerOptions) => import('vite').Plugin);
62+
export default optimizer;
6463
}

index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const DIR = '.vite-plugin-optimizer';
55
const EXT = '.js';
66

77
/**
8-
* @type {import('vite-plugin-optimizer')}
8+
* @type {import('vite-plugin-optimizer')['default']}
99
*/
1010
module.exports = function optimizer(entries, options = {}) {
1111
if (typeof options.dir === 'undefined') options.dir = DIR;
@@ -63,13 +63,13 @@ module.exports = function optimizer(entries, options = {}) {
6363
}
6464

6565
/**
66-
* @type {import('.').GenerateModule}
66+
* @type {import('vite-plugin-optimizer').GenerateModule}
6767
*/
6868
async function generateModule(entries, options) {
6969
const dir = options.dir; // Here, must be absolute path.
7070

7171
/**
72-
* @type {import('.').GenerateRecord[]}
72+
* @type {import('vite-plugin-optimizer').GenerateRecord[]}
7373
*/
7474
const generateRecords = [];
7575
for (const [module, variableType] of Object.entries(entries)) {
@@ -85,7 +85,7 @@ async function generateModule(entries, options) {
8585

8686
let moduleContent = null;
8787
/**
88-
* @type {import('.').GenerateRecord}
88+
* @type {import('vite-plugin-optimizer').GenerateRecord}
8989
*/
9090
let record = { module, filename };
9191

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vite-plugin-optimizer",
3-
"version": "1.4.2",
3+
"version": "1.4.3",
44
"description": "Manually Pre-Bundling of Vite",
55
"main": "index.js",
66
"types": "index.d.ts",

tsconfig.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ES2022",
4+
"module": "ESNext",
5+
"esModuleInterop": true,
6+
"moduleResolution": "Node",
7+
"resolveJsonModule": true,
8+
"strict": true,
9+
"allowJs": true,
10+
"skipLibCheck": true,
11+
"allowSyntheticDefaultImports": true,
12+
"baseUrl": "."
13+
}
14+
}

0 commit comments

Comments
 (0)