Skip to content

Commit 0521023

Browse files
committed
Breaking Change: ESM Modules & rename from "static" to "files"
1 parent fbdc1a7 commit 0521023

File tree

15 files changed

+113
-136
lines changed

15 files changed

+113
-136
lines changed

lib/index.js

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,12 @@
1-
let { FileFinder } = require("./util.js");
2-
let { readFile, stat } = require("node:fs/promises");
3-
let path = require("node:path");
1+
import { FileFinder } from "./util.js";
2+
import { readFile, stat } from "node:fs/promises";
3+
import * as path from "node:path";
44

5-
module.exports = {
6-
key: "static",
7-
bucket: "static",
8-
plugin: faucetStatic
9-
};
5+
export const key = "files";
6+
export const bucket = "static";
107

11-
/**
12-
* The static plugin copies files with an option to define compaction functions
13-
*
14-
* @type FaucetPlugin<Config>
15-
*/
16-
function faucetStatic(config, assetManager, { compact } = {}) {
8+
/** @type FaucetPlugin<Config> */
9+
export function plugin(config, assetManager, { compact } = {}) {
1710
let copiers = config.map(copyConfig =>
1811
makeCopier(copyConfig, assetManager, { compact }));
1912

lib/util.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
let { readdir, stat } = require("node:fs/promises");
2-
let path = require("node:path");
1+
import { readdir, stat } from "node:fs/promises";
2+
import * as path from "node:path";
33

4-
exports.FileFinder = class FileFinder {
4+
export class FileFinder {
55
/**
66
* @param {string} root
77
* @param {FileFinderOptions} options
@@ -42,7 +42,7 @@ exports.FileFinder = class FileFinder {
4242
filter(filename => !filename.startsWith("..")).
4343
filter(this._filter);
4444
}
45-
};
45+
}
4646

4747
/**
4848
* flat list of all files of a directory tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"version": "2.1.0",
44
"description": "static files for faucet-pipeline",
55
"main": "lib/index.js",
6+
"type": "module",
67
"scripts": {
78
"test": "npm run lint && npm run typecheck && npm run test:cli",
89
"test:cli": "./test/run",

test/test_basic/faucet.config.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
"use strict";
2-
let path = require("path");
1+
import { resolve } from "node:path";
32

4-
module.exports = {
5-
static: [{
6-
source: "./src",
7-
target: "./dist"
8-
}],
9-
plugins: [path.resolve(__dirname, "../..")]
10-
};
3+
export const files = [{
4+
source: "./src",
5+
target: "./dist"
6+
}];
7+
8+
export const plugins = [resolve(import.meta.dirname, "../..")];
Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
"use strict";
2-
let path = require("path");
1+
import { resolve } from "node:path";
32

4-
module.exports = {
5-
static: [{
6-
source: "./src",
7-
target: "./dist"
8-
}],
9-
manifest: {
10-
target: "./dist/manifest.json"
11-
},
12-
plugins: [path.resolve(__dirname, "../..")]
3+
export const files = [{
4+
source: "./src",
5+
target: "./dist"
6+
}];
7+
8+
export const manifest = {
9+
target: "./dist/manifest.json"
1310
};
11+
12+
export const plugins = [resolve(import.meta.dirname, "../..")];
Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
"use strict";
2-
let path = require("path");
1+
import { resolve, relative } from "node:path";
32

4-
module.exports = {
5-
static: [{
6-
source: "./src",
7-
target: "./dist"
8-
}],
9-
manifest: {
10-
target: "./dist/manifest.json",
11-
key: (f, targetDir) => path.relative(targetDir, f)
12-
},
13-
plugins: [path.resolve(__dirname, "../..")]
3+
export const files = [{
4+
source: "./src",
5+
target: "./dist"
6+
}];
7+
8+
export const manifest = {
9+
target: "./dist/manifest.json",
10+
key: (f, targetDir) => relative(targetDir, f)
1411
};
12+
13+
export const plugins = [resolve(import.meta.dirname, "../..")];
Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
"use strict";
2-
let path = require("path");
1+
import { resolve, relative } from "node:path";
32

4-
module.exports = {
5-
static: [{
6-
source: "./src/test.txt",
7-
target: "./dist/test.txt"
8-
}],
9-
manifest: {
10-
target: "./dist/manifest.json",
11-
key: (f, targetDir) => path.relative(targetDir, f)
12-
},
13-
plugins: [path.resolve(__dirname, "../..")]
3+
export const files = [{
4+
source: "./src/test.txt",
5+
target: "./dist/test.txt"
6+
}];
7+
8+
export const manifest = {
9+
target: "./dist/manifest.json",
10+
key: (f, targetDir) => relative(targetDir, f)
1411
};
12+
13+
export const plugins = [resolve(import.meta.dirname, "../..")];
Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
"use strict";
2-
let path = require("path");
1+
import { resolve, relative } from "node:path";
32

4-
module.exports = {
5-
static: [{
6-
source: "./src",
7-
target: "./dist"
8-
}],
9-
manifest: {
10-
target: "./dist/manifest.json",
11-
value: f => `/assets/${path.relative("./dist", f)}`
12-
},
13-
plugins: [path.resolve(__dirname, "../..")]
3+
export const files = [{
4+
source: "./src",
5+
target: "./dist"
6+
}];
7+
8+
export const manifest = {
9+
target: "./dist/manifest.json",
10+
value: f => `/assets/${relative("./dist", f)}`
1411
};
12+
13+
export const plugins = [resolve(import.meta.dirname, "../..")];
Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
"use strict";
2-
let path = require("path");
1+
import { resolve } from "node:path";
32

4-
module.exports = {
5-
static: [{
6-
source: "./src",
7-
target: "./dist",
8-
filter: path => path.startsWith("inner/")
9-
}],
10-
plugins: [path.resolve(__dirname, "../..")]
11-
};
3+
export const files = [{
4+
source: "./src",
5+
target: "./dist",
6+
filter: path => path.startsWith("inner/")
7+
}];
8+
9+
export const plugins = [resolve(import.meta.dirname, "../..")];
Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
"use strict";
2-
let path = require("path");
1+
import { resolve } from "node:path";
32

4-
module.exports = {
5-
static: [{
6-
source: "./src",
7-
target: "./dist",
8-
filter: path => path.endsWith(".txt")
9-
}],
10-
plugins: [path.resolve(__dirname, "../..")]
11-
};
3+
export const files = [{
4+
source: "./src",
5+
target: "./dist",
6+
filter: path => path.endsWith(".txt")
7+
}];
8+
9+
export const plugins = [resolve(import.meta.dirname, "../..")];

0 commit comments

Comments
 (0)