@atproto-labs/rollup-plugin-bundle-manifest 0.0.1 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +99 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +9 -3
- package/CHANGELOG.md +0 -7
- package/src/index.ts +0 -76
- package/tsconfig.json +0 -8
package/README.md
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
# @atproto-labs/rollup-plugin-bundle-manifest
|
|
2
|
+
|
|
3
|
+
This Rollup plugin allows to generate a (JSON) manifest containing the output
|
|
4
|
+
files of a Rollup build. The manifest will look as follows:
|
|
5
|
+
|
|
6
|
+
```json
|
|
7
|
+
{
|
|
8
|
+
"main.js": {
|
|
9
|
+
"type": "chunk",
|
|
10
|
+
"mime": "application/javascript",
|
|
11
|
+
"dynamicImports": [],
|
|
12
|
+
"isDynamicEntry": false,
|
|
13
|
+
"isEntry": true,
|
|
14
|
+
"isImplicitEntry": false,
|
|
15
|
+
"name": "main",
|
|
16
|
+
"sha256": "<sha256-hash>",
|
|
17
|
+
"data": "<base64-encoded-contents>"
|
|
18
|
+
},
|
|
19
|
+
"main.js.map": {
|
|
20
|
+
"type": "asset",
|
|
21
|
+
"mime": "application/json",
|
|
22
|
+
"sha256": "<sha256-hash>",
|
|
23
|
+
"data": "<base64-encoded-contents>"
|
|
24
|
+
},
|
|
25
|
+
"main.css": {
|
|
26
|
+
"type": "asset",
|
|
27
|
+
"mime": "text/css",
|
|
28
|
+
"sha256": "<sha256-hash>",
|
|
29
|
+
"data": "<base64-encoded-contents>"
|
|
30
|
+
}
|
|
31
|
+
// ... more entries as needed
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
This manifest will typically be useful for a backend service that serves the
|
|
36
|
+
frontend assets, as it can be used to determine the correct `Content-Type` and
|
|
37
|
+
and file integrity (via the SHA-256 hash), without having to read the files
|
|
38
|
+
themselves.
|
|
39
|
+
|
|
40
|
+
## Usage
|
|
41
|
+
|
|
42
|
+
```js
|
|
43
|
+
// rollup.config.js
|
|
44
|
+
|
|
45
|
+
import bundleManifest from '@atproto-labs/rollup-plugin-bundle-manifest'
|
|
46
|
+
|
|
47
|
+
export default {
|
|
48
|
+
input: 'src/index.js',
|
|
49
|
+
output: {
|
|
50
|
+
dir: 'dist',
|
|
51
|
+
format: 'es',
|
|
52
|
+
},
|
|
53
|
+
plugins: [
|
|
54
|
+
bundleManifest({
|
|
55
|
+
name: 'bundle-manifest.json',
|
|
56
|
+
|
|
57
|
+
// Optional: should the asset data be embedded (as base64 string) in the manifest?
|
|
58
|
+
data: false,
|
|
59
|
+
}),
|
|
60
|
+
],
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Options
|
|
65
|
+
|
|
66
|
+
- `name` (string): The name of the manifest file. Defaults to `bundle-manifest.json`.
|
|
67
|
+
- `data` (boolean): Whether to embed the asset data in the manifest. Defaults to `false`.
|
|
68
|
+
|
|
69
|
+
## Example
|
|
70
|
+
|
|
71
|
+
```js
|
|
72
|
+
const assetManifest = require('./dist/bundle-manifest.json')
|
|
73
|
+
|
|
74
|
+
const app = express()
|
|
75
|
+
|
|
76
|
+
app.use((req, res, next) => {
|
|
77
|
+
const asset = assetManifest[req.path.slice(1)]
|
|
78
|
+
if (!asset) return next()
|
|
79
|
+
|
|
80
|
+
res.setHeader('Content-Type', asset.mime)
|
|
81
|
+
res.setHeader('Content-Length', asset.data.length)
|
|
82
|
+
|
|
83
|
+
res.end(Buffer.from(asset.data, 'base64'))
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
app.use((req, res, next) => {
|
|
87
|
+
res.setHeader(
|
|
88
|
+
'Content-Security-Policy',
|
|
89
|
+
buildCSP(assetManifest), // Not provided here
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
// Serve the index.html file
|
|
93
|
+
res.sendFile('index.html')
|
|
94
|
+
})
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## License
|
|
98
|
+
|
|
99
|
+
MIT
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAE/B,KAAK,SAAS,GAAG;IACf,IAAI,EAAE,OAAO,CAAA;IACb,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,CAAC,EAAE,MAAM,CAAA;CACd,CAAA;AAED,KAAK,SAAS,GAAG;IACf,IAAI,EAAE,OAAO,CAAA;IACb,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,MAAM,CAAA;IACd,cAAc,EAAE,MAAM,EAAE,CAAA;IACxB,cAAc,EAAE,OAAO,CAAA;IACvB,OAAO,EAAE,OAAO,CAAA;IAChB,eAAe,EAAE,OAAO,CAAA;IACxB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,CAAC,EAAE,MAAM,CAAA;CACd,CAAA;AAED,MAAM,MAAM,YAAY,GAAG,SAAS,GAAG,SAAS,CAAA;AAEhD,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAA;AAEnD,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,EACrC,IAA6B,EAC7B,IAAY,GACb,GAAE;IACD,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,OAAO,CAAA;CACV,GAAG,MAAM,CAwCd"}
|
package/dist/index.js
CHANGED
|
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.default = bundleManifest;
|
|
6
7
|
const node_crypto_1 = require("node:crypto");
|
|
7
8
|
const node_path_1 = require("node:path");
|
|
8
9
|
const mime_1 = __importDefault(require("mime"));
|
|
@@ -44,5 +45,4 @@ function bundleManifest({ name = 'bundle-manifest.json', data = false, } = {}) {
|
|
|
44
45
|
},
|
|
45
46
|
};
|
|
46
47
|
}
|
|
47
|
-
exports.default = bundleManifest;
|
|
48
48
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;AA4BA,iCA8CC;AA1ED,6CAAwC;AACxC,yCAAmC;AACnC,gDAAuB;AA0BvB,SAAwB,cAAc,CAAC,EACrC,IAAI,GAAG,sBAAsB,EAC7B,IAAI,GAAG,KAAK,MAIV,EAAE;IACJ,OAAO;QACL,IAAI,EAAE,iBAAiB;QACvB,cAAc,CAAC,aAAa,EAAE,MAAM;YAClC,MAAM,QAAQ,GAAa,EAAE,CAAA;YAE7B,KAAK,MAAM,CAAC,QAAQ,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;gBACvD,IAAI,KAAK,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;oBAC3B,QAAQ,CAAC,QAAQ,CAAC,GAAG;wBACnB,IAAI,EAAE,KAAK,CAAC,IAAI;wBAChB,IAAI,EAAE,IAAI;4BACR,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC;4BAC9C,CAAC,CAAC,SAAS;wBACb,IAAI,EAAE,cAAI,CAAC,OAAO,C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
4
|
"license": "MIT",
|
|
5
5
|
"description": "Library for generating a manifest of bundled files from a Rollup build",
|
|
6
6
|
"keywords": [
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"repository": {
|
|
13
13
|
"type": "git",
|
|
14
14
|
"url": "https://github.com/bluesky-social/atproto",
|
|
15
|
-
"directory": "packages/rollup-plugin-bundle-manifest"
|
|
15
|
+
"directory": "packages/internal/rollup-plugin-bundle-manifest"
|
|
16
16
|
},
|
|
17
17
|
"type": "commonjs",
|
|
18
18
|
"main": "dist/index.js",
|
|
@@ -23,6 +23,12 @@
|
|
|
23
23
|
"default": "./dist/index.js"
|
|
24
24
|
}
|
|
25
25
|
},
|
|
26
|
+
"engines": {
|
|
27
|
+
"node": ">=18.7.0"
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"dist"
|
|
31
|
+
],
|
|
26
32
|
"dependencies": {
|
|
27
33
|
"mime": "^3.0.0"
|
|
28
34
|
},
|
|
@@ -31,7 +37,7 @@
|
|
|
31
37
|
},
|
|
32
38
|
"devDependencies": {
|
|
33
39
|
"rollup": "^4.10.0",
|
|
34
|
-
"typescript": "^5.
|
|
40
|
+
"typescript": "^5.6.3"
|
|
35
41
|
},
|
|
36
42
|
"scripts": {
|
|
37
43
|
"build": "tsc --build tsconfig.json"
|
package/CHANGELOG.md
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
# @atproto-labs/rollup-plugin-bundle-manifest
|
|
2
|
-
|
|
3
|
-
## 0.0.1
|
|
4
|
-
|
|
5
|
-
### Patch Changes
|
|
6
|
-
|
|
7
|
-
- [`e134c79a0`](https://github.com/bluesky-social/atproto/commit/e134c79a0ffb000b2cb36437815673fa6bda664b) Thanks [@devinivy](https://github.com/devinivy)! - Initial publish of experimental oauth packages to @atproto-labs
|
package/src/index.ts
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { createHash } from 'node:crypto'
|
|
2
|
-
import { extname } from 'node:path'
|
|
3
|
-
|
|
4
|
-
import mime from 'mime'
|
|
5
|
-
import { Plugin } from 'rollup'
|
|
6
|
-
|
|
7
|
-
type AssetItem = {
|
|
8
|
-
type: 'asset'
|
|
9
|
-
mime?: string
|
|
10
|
-
sha256: string
|
|
11
|
-
data?: string
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
type ChunkItem = {
|
|
15
|
-
type: 'chunk'
|
|
16
|
-
mime: string
|
|
17
|
-
sha256: string
|
|
18
|
-
dynamicImports: string[]
|
|
19
|
-
isDynamicEntry: boolean
|
|
20
|
-
isEntry: boolean
|
|
21
|
-
isImplicitEntry: boolean
|
|
22
|
-
name: string
|
|
23
|
-
data?: string
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export type ManifestItem = AssetItem | ChunkItem
|
|
27
|
-
|
|
28
|
-
export type Manifest = Record<string, ManifestItem>
|
|
29
|
-
|
|
30
|
-
export default function bundleManifest({
|
|
31
|
-
name = 'bundle-manifest.json',
|
|
32
|
-
data = false,
|
|
33
|
-
}: {
|
|
34
|
-
name?: string
|
|
35
|
-
data?: boolean
|
|
36
|
-
} = {}): Plugin {
|
|
37
|
-
return {
|
|
38
|
-
name: 'bundle-manifest',
|
|
39
|
-
generateBundle(outputOptions, bundle) {
|
|
40
|
-
const manifest: Manifest = {}
|
|
41
|
-
|
|
42
|
-
for (const [fileName, chunk] of Object.entries(bundle)) {
|
|
43
|
-
if (chunk.type === 'asset') {
|
|
44
|
-
manifest[fileName] = {
|
|
45
|
-
type: chunk.type,
|
|
46
|
-
data: data
|
|
47
|
-
? Buffer.from(chunk.source).toString('base64')
|
|
48
|
-
: undefined,
|
|
49
|
-
mime: mime.getType(extname(fileName)) || undefined,
|
|
50
|
-
sha256: createHash('sha256').update(chunk.source).digest('base64'),
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
if (chunk.type === 'chunk') {
|
|
55
|
-
manifest[fileName] = {
|
|
56
|
-
type: chunk.type,
|
|
57
|
-
data: data ? Buffer.from(chunk.code).toString('base64') : undefined,
|
|
58
|
-
mime: 'application/javascript',
|
|
59
|
-
sha256: createHash('sha256').update(chunk.code).digest('base64'),
|
|
60
|
-
dynamicImports: chunk.dynamicImports,
|
|
61
|
-
isDynamicEntry: chunk.isDynamicEntry,
|
|
62
|
-
isEntry: chunk.isEntry,
|
|
63
|
-
isImplicitEntry: chunk.isImplicitEntry,
|
|
64
|
-
name: chunk.name,
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
this.emitFile({
|
|
70
|
-
type: 'asset',
|
|
71
|
-
fileName: name,
|
|
72
|
-
source: JSON.stringify(manifest, null, 2),
|
|
73
|
-
})
|
|
74
|
-
},
|
|
75
|
-
}
|
|
76
|
-
}
|