Skip to content

Commit

Permalink
Restore CJS exports (#541)
Browse files Browse the repository at this point in the history
* Restore CJS exports

* make code compile in cjs mode
  • Loading branch information
ericanderson authored Jul 30, 2024
1 parent d316acb commit 9eb7c6e
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 16 deletions.
5 changes: 5 additions & 0 deletions .changeset/weak-masks-suffer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@osdk/foundry-sdk-generator": patch
---

Restore cjs exports
3 changes: 2 additions & 1 deletion .monorepolint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -483,12 +483,13 @@ NOTE: DO NOT EDIT THIS README BY HAND. It is generated by monorepolint.
tsVersion: LATEST_TYPESCRIPT_DEP,
}),

// internal packages depend on the cjs nature of this package! Do not make esmOnly without
// fixing the internal packages first (and bumping major).
...standardPackageRules({
includePackages: ["@osdk/foundry-sdk-generator"],
}, {
legacy: false,
tsVersion: LATEST_TYPESCRIPT_DEP,
esmOnly: true,
customTsconfigExcludes: [
"./src/__e2e_tests__/**/**.test.ts",
"./src/generatedNoCheck/**/*",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env node

// Internally, there is code that invokes the CLI this way (not via normal npm execution)
// so we have this file to ensure we don't break them.
const cli = require("@osdk/foundry-sdk-generator");
cli.cli();
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,19 @@
* limitations under the License.
*/

import { execa } from "execa";
import { execa, execaNode } from "execa";
import { describe, expect, it } from "vitest";

describe("foundry-sdk-generator", () => {
it("should do a basic execution", async () => {
expect(true).toBe(true);
it(
"should do a basic execution via pnpm exec",
{ timeout: 10_000 },
async () => {
expect(true).toBe(true);

const { stdout } = await execa`pnpm exec foundry-sdk-generator --help`;
const { stdout } = await execa`pnpm exec foundry-sdk-generator --help`;

expect(stdout).toMatchInlineSnapshot(`
expect(stdout).toMatchInlineSnapshot(`
"foundry-sdk-generator.cjs <command>
Commands:
Expand All @@ -34,6 +37,28 @@ describe("foundry-sdk-generator", () => {
--help Show help [boolean]
--version Show version number [boolean]"
`);
},
);

it("should do a basic execution via simulated internal mechanism", {
timeout: 10_000,
}, async () => {
expect(true).toBe(true);

const { stdout } =
await execaNode`${__dirname}/../bin/simulate-internal-foundry-sdk-generator.cjs --help`;

expect(stdout).toMatchInlineSnapshot(`
"simulate-internal-foundry-sdk-generator.cjs <command>
Commands:
simulate-internal-foundry-sdk-generator. Generates a new npm package which
cjs generatePackage can be published
Options:
--help Show help [boolean]
--version Show version number [boolean]"
`);
});
}, { timeout: 10_000 });
});
//
8 changes: 5 additions & 3 deletions packages/foundry-sdk-generator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,18 @@
},
"exports": {
".": {
"require": "./build/cjs/index.cjs",
"browser": "./build/browser/index.js",
"import": "./build/esm/index.js"
},
"./*": {
"require": "./build/cjs/public/*.cjs",
"browser": "./build/browser/public/*.js",
"import": "./build/esm/public/*.js"
}
},
"scripts": {
"check-attw": "monorepo.tool.attw esm",
"check-attw": "monorepo.tool.attw both",
"check-spelling": "cspell --quiet .",
"clean": "rm -rf lib dist types build tsconfig.tsbuildinfo",
"fix-lint": "eslint . --fix && dprint fmt --config $(find-up dprint.json)",
Expand All @@ -28,7 +30,7 @@
"test:watch": "vitest",
"transpile": "monorepo.tool.transpile",
"transpileWatch": "tsup --watch",
"typecheck": "monorepo.tool.typecheck esm"
"typecheck": "monorepo.tool.typecheck both"
},
"dependencies": {
"@osdk/api": "workspace:~",
Expand Down Expand Up @@ -74,6 +76,6 @@
],
"main": "./build/cjs/index.cjs",
"module": "./build/esm/index.js",
"types": "./build/esm/index.d.ts",
"types": "./build/cjs/index.d.cts",
"type": "module"
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,12 @@ async function createRollupBuild(
browser: true,
modulePaths: [nodeModulesPath!],
}),
(commonjs.default ?? (commonjs as any as typeof commonjs["default"]))({}),
(nodePolyfill.default
?? (nodePolyfill as any as typeof nodePolyfill["default"]))(),
("default" in commonjs
? commonjs.default
: (commonjs as any))({}),
("default" in nodePolyfill
? nodePolyfill.default
: (nodePolyfill as any))(),
],
onwarn: (warning, warn) => {
// Ignore circular dependency warnings
Expand Down
4 changes: 1 addition & 3 deletions packages/foundry-sdk-generator/tsup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,5 @@
import { defineConfig } from "tsup";

export default defineConfig(async (options) =>
(await import("@osdk/monorepo.tsup")).default(options, {
esmOnly: true,
})
(await import("@osdk/monorepo.tsup")).default(options, {})
);

0 comments on commit 9eb7c6e

Please sign in to comment.