Thanks to visit codestin.com
Credit goes to github.com

Skip to content

refactor: migrate to esm#2021

Merged
andriimredocly merged 34 commits into
v2from
refactor/migrate-to-esm
Mar 24, 2025
Merged

refactor: migrate to esm#2021
andriimredocly merged 34 commits into
v2from
refactor/migrate-to-esm

Conversation

@tatomyr
Copy link
Copy Markdown
Collaborator

@tatomyr tatomyr commented Mar 20, 2025

What/Why/How?

WIP

Reference

Testing

Screenshots (optional)

Check yourself

  • Code changed? - Tested with redoc/reference-docs/workflows (internal)
  • All new/updated code is covered with tests
  • New package installed? - Tested in different environments (browser/node)

Security

  • Security impact of change has been considered
  • Code follows company security practices and guidelines

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Mar 20, 2025

⚠️ No Changeset found

Latest commit: 28ac568

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@tatomyr tatomyr requested a review from andriimredocly March 20, 2025 21:14
Comment thread packages/cli/src/index.ts Outdated
if (!('replaceAll' in String.prototype)) {
require('core-js/actual/string/replace-all');
}
// FIXME: this is not working
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be investigated.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be removed.

Comment thread package.json
Comment thread package.json
"release": "changeset publish",
"pack:prepare": "./scripts/local-pack.sh",
"respect:parser:generate": "pegjs --format commonjs packages/respect-core/src/modules/runtime-expressions/abnf-parser.pegjs",
"respect:parser:generate": "pegjs --format commonjs --output packages/respect-core/lib/modules/runtime-expressions/abnf-parser.cjs packages/respect-core/src/modules/runtime-expressions/abnf-parser.pegjs && cp packages/respect-core/lib/modules/runtime-expressions/abnf-parser.cjs packages/respect-core/src/modules/runtime-expressions/abnf-parser.cjs",
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Store abnf-parser.cjs in the lib/ folder (as we actually need it there) but copy it back in src/ so Typescript doesn't fail.

Comment thread packages/cli/src/index.ts Outdated
Comment thread packages/core/package.json
configDir,
// Plugins imported from the node_modules in the package install directory (for example, npx cache directory)
__dirname,
__dirname, // FIXME: use path.dirname(fileURLToPath(import.meta.url))?
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andriimredocly What do you think?

const mod = await import(pathToFileURL(absolutePluginPath).href);
requiredPlugin = mod.default || mod;
}
// try {
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either remove or fix it.

Comment thread packages/core/src/format/format.ts Outdated
Comment thread packages/respect-core/tsconfig.json Outdated
Comment on lines +4 to +5
// "target": "ESNext",
// "module": "CommonJS",
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// "target": "ESNext",
// "module": "CommonJS",

Comment thread tsconfig.json Outdated
Comment thread packages/respect-core/src/modules/__tests__/flow-runner/run-step.test.ts Outdated
type ArazzoDefinition,
type ExtendedOperation,
} from '@redocly/openapi-core/lib/typings/arazzo';
} from 'core/src/typings/openapi.js';
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please imiport from '@redocly/openapi-core'

Copy link
Copy Markdown
Collaborator Author

@tatomyr tatomyr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@andriimredocly andriimredocly marked this pull request as ready for review March 24, 2025 13:22
@andriimredocly andriimredocly requested a review from a team as a code owner March 24, 2025 13:22
@andriimredocly andriimredocly merged commit 7f30527 into v2 Mar 24, 2025
@andriimredocly andriimredocly deleted the refactor/migrate-to-esm branch March 24, 2025 13:25
andriimredocly added a commit that referenced this pull request Mar 24, 2025
* TO_DELETE: tests setup

* migration

* migrating more files for ESM

* migrating more files for ESM

* to be continued...

* fix lint e2e tests

* fix (almost) commands e2e suite

* fix most of respect e2e tests (only one remains)

* fix most of the unit tests (5 left)

* new require

* new require

* up

* update snaphot

* revert changes

* add extension to the rest of imports in the codebase

* use the lib reference instead of src

* add exports section to respect-core package.json

* remove @redocly/openapi-core/lib/utils.js import in favour of root import

* remove @redocly/openapi-core/lib/config/index.js import in favour of root import

* remove @redocly/openapi-core/lib/bundle.js import in favour of root import

* remove @redocly/openapi-core/lib/typings/openapi.js import in favour of root import

* remove @redocly/openapi-core/lib/config/types.js import in favour of root import

* remove @redocly/openapi-core/lib/typings/arazzo.js import in favour of root import

* Update packages/cli/src/index.ts

* Update packages/core/src/format/format.ts

* Update packages/respect-core/src/modules/__tests__/flow-runner/run-step.test.ts

* Update tsconfig.json

* remove core-js lib and relevant things

* fixes for the config-resolver.ts: replace __dirname with ESM-comptible analog, delete comments and fixme

* unify tsconfig.json builds

* remove allowJs from respect-core

* replace require.resolve with a compatible analog

* package.json for core and respect-core migration to ESM

* use relative import instead of absolute one

---------

Co-authored-by: Andrii Maryskevych <[email protected]>
andriimredocly pushed a commit that referenced this pull request Mar 24, 2025
andriimredocly pushed a commit that referenced this pull request Mar 24, 2025
tatomyr added a commit that referenced this pull request Mar 24, 2025
andriimredocly pushed a commit that referenced this pull request Apr 1, 2025
andriimredocly pushed a commit that referenced this pull request Apr 9, 2025
tatomyr added a commit that referenced this pull request Apr 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants