-
Notifications
You must be signed in to change notification settings - Fork 2
v3.1.0 #150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
v3.1.0 #150
Changes from all commits
17dfc2f
93d35ec
82a7635
1a40eb5
b8ad295
c9c4c9f
85af017
73777b8
7bf71e2
3bf9b98
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -2,9 +2,9 @@ | |||||
|
||||||
let { Manifest } = require("./manifest"); | ||||||
let { createFile } = require("./util/files"); | ||||||
let { resolvePath } = require("./util/resolve"); | ||||||
let { reportFileStatus, abort, generateFingerprint } = require("./util"); | ||||||
let { reportFileStatus, abort, resolvePath } = require("./util"); | ||||||
let path = require("path"); | ||||||
let crypto = require("crypto"); | ||||||
|
||||||
exports.AssetManager = class AssetManager { | ||||||
constructor(referenceDir, { manifestConfig, fingerprint, exitOnError } = {}) { | ||||||
|
@@ -43,18 +43,27 @@ exports.AssetManager = class AssetManager { | |||||
}); | ||||||
} | ||||||
|
||||||
get packagesDir() { | ||||||
let memo = this._packagesDir; | ||||||
if(!memo) { | ||||||
memo = this._packagesDir = this.resolvePath("./node_modules"); | ||||||
} | ||||||
return memo; | ||||||
} | ||||||
|
||||||
_updateManifest(originalPath, actualPath, targetDir) { | ||||||
let { referenceDir } = this; | ||||||
originalPath = path.relative(referenceDir, originalPath); | ||||||
actualPath = path.relative(referenceDir, actualPath); | ||||||
return this.manifest.set(originalPath, actualPath, targetDir); | ||||||
} | ||||||
}; | ||||||
|
||||||
function generateFingerprint(filepath, data) { | ||||||
let filename = path.basename(filepath); | ||||||
let ext = filename.indexOf(".") === -1 ? "" : "." + filename.split(".").pop(); | ||||||
let name = ext.length === 0 ? filename : path.basename(filepath, ext); | ||||||
let hash = generateHash(data); | ||||||
return path.join(path.dirname(filepath), `${name}-${hash}${ext}`); | ||||||
} | ||||||
|
||||||
// exported for testing | ||||||
exports.generateFingerprint = generateFingerprint; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
That makes it explicit; cf. |
||||||
|
||||||
function generateHash(str) { | ||||||
let hash = crypto.createHash("md5"); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we perhaps change this to SHA-256? I realize that might be a backwards-compatibility concern though...
|
||||||
hash.update(str); | ||||||
return hash.digest("hex"); | ||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
export interface FaucetPlugin<T> { | ||
(config: T[], assetManager: AssetManager, options: FaucetPluginOptions): FaucetPluginFunc | ||
} | ||
|
||
export interface FaucetPluginFunc { | ||
(filepaths: string[]): Promise<unknown> | ||
} | ||
|
||
export interface FaucetPluginOptions { | ||
sourcemaps: boolean, | ||
compact: boolean | ||
} | ||
|
||
export interface AssetManager { | ||
resolvePath: (path: string, opts?: ResolvePathOpts) => string | ||
writeFile: (targetPath: string, content: Buffer, options: WriteFileOpts) => Promise<unknown> | ||
} | ||
|
||
export interface ResolvePathOpts { | ||
enforceRelative?: boolean | ||
} | ||
|
||
export interface WriteFileOpts { | ||
targetDir: string, | ||
fingerprint?: boolean | ||
} |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we not using
path.extname
here? (See potentially related discussion forfaucet-static
/static-images
.)(Though we might reasonably opt not to risk changing the implementation here, due to backwards-compatibility concerns.)