Skip to content
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

refactor!(secretlint): convert to ESM - top down #529

Merged
merged 34 commits into from
Jul 1, 2023
Merged

refactor!(secretlint): convert to ESM - top down #529

merged 34 commits into from
Jul 1, 2023

Conversation

azu
Copy link
Member

@azu azu commented Jul 1, 2023

Convert each packages to Pure ESM.

Approach

  • Target: secretlint packages
  • Non Target: secretlint rule package

Apply Top Down Approach.

Get dependency graph via Explore the Project Graph.

npx nx graph

graph

  1. @secretlint/quick-start
  2. secretlint
  3. node/tester
  4. formatter/node/config-creator/messages-to-markdown/config-loader/core
  5. types/profile

@secretlint/types should be dual package.
Because, CJS can not load types of ESM packages.

// if @secretlint/types is pure ESM, can not load it from CommonJS
import type { SecretLintRuleMessageTranslate } from "@secretlint/types";

By making @secretlint/types a dual package, the types can be used from both CJS and ESM.

Changes

  • Convert to Pure ESM package
    • If your scripts are CommonJS, you need to dynamic import import("@secretlint/core").
    • For command line/Docker user, No change anything!
  • Convert @secretlint/types to dual package
  • Add new "json" formatter for secretlint
    • output format is changed from old "json" formatter
  • @secretlint/tester is migrated to ESM, But we can load it using dynamic import from CJS
    • Use node:test instead of Mocha
    • Support URL object in snapshotDirectory option.
- import { snapshot } from "@secretlint/tester");
import path from "path";
import { creator as rule } from "../src/index";
+ import test from "node:test";
+ (async function () {
+   const snapshot = (await import("@secretlint/tester")).snapshot;
-    describe("@secretlint/secretlint-rule-preset-canary", () => {
+    test("@secretlint/secretlint-rule-preset-canary", async (t) => {
-        snapshot({
+        return snapshot({
            defaultConfig: {
                rules: [
                    {
                        id: "@secretlint/secretlint-rule-preset-canary",
                        rule,
                        rules: [],
                        options: {},
                    },
                ],
            },
            updateSnapshot: !!process.env.UPDATE_SNAPSHOT,
            snapshotDirectory: path.join(__dirname, "snapshots"),
        }).forEach((name, test) => {
-            it(name, async function () {
+            return it(name, async (context) => {
                const status = await test();
                if (status === "skip") {
-                    this.skip();
+                    context.skip();
                }
            });
        });
    });
+});

Not Changes

  • Each rules are written as CommonJS
  • It will be separated PRs.

@azu azu added the Type: Breaking Change Includes breaking changes label Jul 1, 2023
@azu azu merged commit 4373bf9 into master Jul 1, 2023
16 checks passed
@azu azu deleted the feature/esm branch July 1, 2023 14:10
@azu azu mentioned this pull request Jul 1, 2023
20 tasks
@github-actions github-actions bot mentioned this pull request Jul 2, 2023
@azu azu changed the title refactor!(secretlint): convert to ESM refactor!(secretlint): convert to ESM - top down Jul 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Breaking Change Includes breaking changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Core Packags: Convert to ESM
1 participant