Skip to content

Commit

Permalink
Fix commonjs not working
Browse files Browse the repository at this point in the history
  • Loading branch information
zackliu committed Sep 22, 2023
1 parent 30c703f commit d798b40
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 14 deletions.
24 changes: 15 additions & 9 deletions common/config/rush/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 9 additions & 5 deletions sdk/web-pubsub/web-pubsub-client-protobuf/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@azure/web-pubsub-client-protobuf",
"version": "1.0.0-beta.1",
"version": "1.0.0-beta.2",
"description": "Azure Web PubSub Client Protobuf",
"sdk-type": "client",
"main": "dist/index.js",
Expand All @@ -11,11 +11,11 @@
"types": "types/web-pubsub-client-protobuf.d.ts",
"scripts": {
"audit": "node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit",
"build:browser": "npm run build-protobuf && tsc -p . && npm run copy-files && dev-tool run bundle",
"build:node": "npm run build-protobuf && tsc -p . && npm run copy-files && dev-tool run bundle",
"build:browser": "npm run build-protobuf && tsc -p . && npm run copy-files && rollup -c",
"build:node": "npm run build-protobuf && tsc -p . && npm run copy-files && rollup -c",
"build:samples": "dev-tool samples publish -f",
"build:test": "npm run build-protobuf && tsc -p . && npm run copy-files && dev-tool run bundle",
"build": "npm run clean && npm run build-protobuf && tsc -p . && npm run copy-files && dev-tool run bundle && api-extractor run --local",
"build:test": "npm run build-protobuf && tsc -p . && npm run copy-files && rollup -c",
"build": "npm run clean && npm run build-protobuf && tsc -p . && npm run copy-files && rollup -c && api-extractor run --local",
"copy-files": "copyfiles ./src/generated/clientProto.js ./dist-esm/",
"build-protobuf": "pbjs -t static-module -w es6 -o ./src/generated/clientProto.js ./src/protos/client.proto && pbts -o ./src/generated/clientProto.d.ts ./src/generated/clientProto.js",
"check-format": "prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"",
Expand Down Expand Up @@ -70,6 +70,10 @@
"@azure/dev-tool": "^1.0.0",
"@azure/eslint-plugin-azure-sdk": "^3.0.0",
"@microsoft/api-extractor": "^7.31.1",
"@rollup/plugin-commonjs": "^24.0.0",
"@rollup/plugin-node-resolve": "^13.1.3",
"rollup": "^2.78.0",
"rollup-plugin-sourcemaps": "^0.6.2",
"@types/chai": "^4.1.6",
"@types/chai-as-promised": "^7.1.5",
"@types/express": "^4.16.0",
Expand Down
33 changes: 33 additions & 0 deletions sdk/web-pubsub/web-pubsub-client-protobuf/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import nodeBuiltins from "builtin-modules";
import nodeResolve from "@rollup/plugin-node-resolve";
import cjs from "@rollup/plugin-commonjs";
import sourcemaps from "rollup-plugin-sourcemaps";

export function makeConfig(pkg) {
if (!pkg.module) {
log.error(pkg.name, "does not specify a `module` field.");
return false;
}

const baseConfig = {
// Use the package's module field if it has one
input: pkg.module,
external: [
...nodeBuiltins,
...Object.keys(pkg.dependencies),
...Object.keys(pkg.devDependencies),
],
output: {
file: "dist/index.js",
format: "cjs",
sourcemap: true,
exports: "named",
},
preserveSymlinks: false,
plugins: [sourcemaps(), cjs(), nodeResolve()],
};

return baseConfig;
}

export default makeConfig(require("./package.json"));

0 comments on commit d798b40

Please sign in to comment.