feat(zip)!: Update packaging for NESM/RESM bridge
BREAKING CHANGE: No longer supports direct use from CommonJS
MODIFY
packages/zip/NEWS.md
packages/zip/NEWS.md
+# Next release
+
+- Initial version.

MODIFY
packages/zip/index.d.ts
packages/zip/index.d.ts
-export { readZip, writeZip } from './src/main.js';
-export { ZipReader } from './src/reader.js';
-export { ZipWriter } from './src/writer.js';
+export { ZipReader, readZip, ZipWriter, writeZip } from './index.js';

MODIFY
packages/zip/index.js
packages/zip/index.js
-export { readZip, writeZip } from './src/main.js';
-export { ZipReader } from './src/reader.js';
-export { ZipWriter } from './src/writer.js';
+export { ZipReader, readZip } from './src/reader.js';
+export { ZipWriter, writeZip } from './src/writer.js';

MODIFY
packages/zip/package.json
packages/zip/package.json
"name": "@endo/zip",
"version": "0.1.0",
"description": "A minimal, synchronous Zip reader and writer",
- "keywords": [],
+ "keywords": ["zip", "ses", "endo"],
"author": "Endo contributors",
"license": "Apache-2.0",
"homepage": "https://github.com/endojs/endo/tree/master/packages/zip#readme",
"url": "https://github.com/endojs/endo/issues"
},
"type": "module",
- "parsers": {
- "js": "mjs"
- },
- "main": "./dist/zip.cjs",
- "module": "./index.js",
- "browser": "./dist/zip.umd.js",
- "unpkg": "./dist/zip.umd.js",
+ "main": "./index.js",
"types": "./index.d.ts",
"exports": {
- "./package.json": "./package.json",
- ".": {
- "import": "./index.js",
- "require": "./dist/zip.cjs",
- "browser": "./dist/zip.umd.js"
- }
+ ".": "./index.js",
+ "./reader.js": "./reader.js",
+ "./writer.js": "./writer.js",
+ "./package.json": "./package.json"
},
"scripts": {
- "build": "rollup --config rollup.config.js",
- "clean": "rm -rf dist",
- "cover": "nyc ava",
+ "build": "exit 0",
"lint": "yarn lint:types && yarn lint:js",
- "lint-fix": "eslint --fix '*.js' '**/*.js' 'test*/**.js'",
- "lint:js": "eslint '*.js' '**/*.js' 'test*/**.js'",
+ "lint-fix": "eslint --fix '**/*.js'",
+ "lint:js": "eslint '**/*.js'",
"lint:types": "tsc --build jsconfig.json",
- "prepublish": "yarn clean && yarn build",
"test": "ava"
},
- "dependencies": {},
"devDependencies": {
- "@rollup/plugin-commonjs": "^13.0.0",
- "@rollup/plugin-node-resolve": "^6.1.0",
+ "@agoric/eslint-config": "^0.3.6",
"ava": "^3.12.1",
"babel-eslint": "^10.0.3",
"eslint": "^7.23.0",
"eslint-plugin-eslint-comments": "^3.1.2",
"eslint-plugin-import": "^2.19.1",
"eslint-plugin-prettier": "^3.1.2",
- "nyc": "^15.1.0",
"prettier": "^1.19.1",
- "rollup": "1.31.0",
- "rollup-plugin-terser": "^5.1.3",
"typescript": "^4.0.5"
},
"files": [
"LICENSE*",
- "dist",
+ "index.d.ts",
+ "index.js",
+ "reader.js",
+ "writer.js",
"src",
"types"
],
+ "private": false,
"publishConfig": {
"access": "public"
},

ADD
packages/zip/reader.js
+export { ZipReader } from './src/reader.js';

DELETE
packages/zip/rollup.config.js
-import resolve from '@rollup/plugin-node-resolve';
-import commonjs from '@rollup/plugin-commonjs';
-import { terser } from 'rollup-plugin-terser';
-import fs from 'fs';
-
-const metaPath = new URL('package.json', import.meta.url).pathname;
-const meta = JSON.parse(fs.readFileSync(metaPath, 'utf-8'));
-const name = meta.name.split('/').pop();
-const umd = meta.umd || name;
-
-export default [
- {
- input: 'src/main.js',
- output: [
- {
- file: `dist/${name}.mjs`,
- format: 'esm',
- },
- {
- file: `dist/${name}.cjs`,
- format: 'cjs',
- },
- ],
- plugins: [resolve(), commonjs()],
- },
- {
- input: 'src/main.js',
- output: {
- file: `dist/${name}.umd.js`,
- format: 'umd',
- name: umd,
- },
- plugins: [resolve(), commonjs()],
- },
- {
- input: 'src/main.js',
- output: {
- file: `dist/${name}.umd.min.js`,
- format: 'umd',
- name: umd,
- },
- plugins: [resolve(), commonjs(), terser()],
- },
-];

DELETE
packages/zip/src/main.js
-// @ts-check
-
-/**
- * Decouples Zip usage from JSZip's particular presentation.
- */
-
-import { ZipReader } from './reader.js';
-import { ZipWriter } from './writer.js';
-
-/**
- * @param {Uint8Array} data
- * @param {string} location
- * @returns {Promise<ArchiveReader>}
- */
-export const readZip = async (data, location) => {
- const reader = new ZipReader(data, { name: location });
- /** @type {ReadFn} */
- const read = async path => reader.read(path);
- return { read };
-};
-
-/**
- * @returns {ArchiveWriter}
- */
-export const writeZip = () => {
- const writer = new ZipWriter();
- /** @type {WriteFn} */
- const write = async (path, data) => {
- writer.write(path, data);
- };
- /** @type {SnapshotFn} */
- const snapshot = async () => writer.snapshot();
- return { write, snapshot };
-};

MODIFY
packages/zip/src/reader.js
packages/zip/src/reader.js
// @ts-check
import { BufferReader } from './buffer-reader.js';
-import { readZip } from './format-reader.js';
+import { readZip as readZipFormat } from './format-reader.js';
export class ZipReader {
/**
@@ -12,7 +12,7 @@ export class ZipReader {
constructor(data, options = {}) {
const { name = '<unknown>' } = options;
const reader = new BufferReader(data);
- this.files = readZip(reader);
+ this.files = readZipFormat(reader);
this.name = name;
}
@@ -45,3 +45,15 @@ export class ZipReader {
};
}
}
+
+/**
+ * @param {Uint8Array} data
+ * @param {string} location
+ * @returns {Promise<ArchiveReader>}
+ */
+export const readZip = async (data, location) => {
+ const reader = new ZipReader(data, { name: location });
+ /** @type {ReadFn} */
+ const read = async path => reader.read(path);
+ return { read };
+};

MODIFY
packages/zip/src/writer.js
packages/zip/src/writer.js
// @ts-check
import { BufferWriter } from './buffer-writer.js';
-import { writeZip } from './format-writer.js';
+import { writeZip as writeZipFormat } from './format-writer.js';
export class ZipWriter {
/**
@@ -44,7 +44,21 @@ export class ZipWriter {
*/
snapshot() {
const writer = new BufferWriter();
- writeZip(writer, Array.from(this.files.values()));
+ writeZipFormat(writer, Array.from(this.files.values()));
return writer.subarray();
}
}
+
+/**
+ * @returns {ArchiveWriter}
+ */
+export const writeZip = () => {
+ const writer = new ZipWriter();
+ /** @type {WriteFn} */
+ const write = async (path, data) => {
+ writer.write(path, data);
+ };
+ /** @type {SnapshotFn} */
+ const snapshot = async () => writer.snapshot();
+ return { write, snapshot };
+};

ADD
packages/zip/writer.js
+export { ZipWriter } from './src/writer.js';

feat(zip)!: Update packaging for NESM/RESM bridge

BREAKING CHANGE: No longer supports direct use from CommonJS