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

feat(dev-server): export package version #7305

Merged
merged 3 commits into from
Aug 5, 2024

Conversation

leimonio
Copy link
Contributor

Summary

I was looking in a convenient way of getting the version of the @rsapck/dev-server similar to what is available in @rspack/core

Export version from package.json (similar to the @rspack/core)

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

@SoonIter
Copy link
Member

At present, users need to use the same version of @rspack/core and @rspack/dev-server

"devDependencies": {
     "@rspack/core": "0.7.5",
     "@rspack/dev-server": "0.7.5"
}

Have you encountered any issues? :D

@leimonio
Copy link
Contributor Author

So getting the version from @rspack/core should do the job?

I believe even if this is the case, since the 2 modules are separate they'd still need to expose their own version.

@SoonIter
Copy link
Member

@chenjiahan cc

@chenjiahan
Copy link
Member

How about getting the version from package.json?

import pkgJson from '@rspack/dev-server/package.json';

console.log(pkgJson.version);

@chenjiahan
Copy link
Member

I believe even if this is the case, since the 2 modules are separate they'd still need to expose their own version.

Agree with this.

@leimonio
Copy link
Contributor Author

leimonio commented Jul 25, 2024 via email

packages/rspack-dev-server/src/index.ts Outdated Show resolved Hide resolved
packages/rspack/src/exports.ts Outdated Show resolved Hide resolved
@chenjiahan chenjiahan changed the title chore(dev-server): export rspack version feat(dev-server): export rspack version Jul 26, 2024
@chenjiahan chenjiahan changed the title feat(dev-server): export rspack version feat(dev-server): export package version Jul 26, 2024
@github-actions github-actions bot added the release: feature release: feature related release(mr only) label Jul 26, 2024
@leimonio
Copy link
Contributor Author

Export from @rspack/core exports webpack version as version, and @rspack/dev-server exports rspack dev server as version. This will be confusing, as I'd expect both modules to reference the respective package version.

@chenjiahan
Copy link
Member

@rspack/core exports the webpack version to be compatible with the webpack ecosystem, and @rspack/dev-server does not need this. Therefore the meaning of their exported version are different.

Copy link

netlify bot commented Aug 1, 2024

Deploy Preview for rspack canceled.

Built without sensitive environment variables

Name Link
🔨 Latest commit f641012
🔍 Latest deploy log https://app.netlify.com/sites/rspack/deploys/66b08df91e66500008b1c841

@chenjiahan
Copy link
Member

@leimonio I want to confirm how this.RspackDS is imported?

  1. import * as RspackDS from '@rspack/dev-server';
  2. import RspackDS from '@rspack/dev-server';

@leimonio
Copy link
Contributor Author

leimonio commented Aug 2, 2024

In my case it's a bit more abstracted, and also relies on CommonJS in this way:

export class BitRspackDevServer implements DevServer {
  private readonly Rspack: typeof RspackCompiler;
  private readonly RspackDS: typeof RspackDS;

  id = 'rspack-dev-server';

  displayName = 'Rspack dev server';

  constructor(
    private config: Configuration,
    private rspackModulePath: string = require.resolve('@rspack/core'),
    private rspackDevServerModulePath: string = require.resolve(
      '@rspack/dev-server'
    )
  ) {
    this.Rspack = require(this.rspackModulePath);
    this.RspackDS = require(this.rspackDevServerModulePath).RspackDevServer;
  }
  ...
  } // end of class

Basically, BitRspackDevServer consumer is able to define their own path resolving @rspack/dev-server from.
Path to @rspack/dev-server defaults to require.resolve('@rspack/dev-server').

@chenjiahan
Copy link
Member

I see, so we need to add the version to the RspackDevServer class:

export class RspackDevServer extends WebpackDevServer {
  static version = 'a.b.c';
}

And users can access the version via:

this.RspackDS = require('@rspack/dev-server').RspackDevServer;
console.log(this.RspackDS.version);

@SoonIter SoonIter force-pushed the main branch 2 times, most recently from 13aace3 to 2653071 Compare August 5, 2024 08:05
Copy link
Member

@chenjiahan chenjiahan left a comment

Choose a reason for hiding this comment

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

LGTM 👍🏻

@chenjiahan chenjiahan merged commit 9347ecc into web-infra-dev:main Aug 5, 2024
28 checks passed
@chenjiahan chenjiahan mentioned this pull request Aug 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release: feature release: feature related release(mr only)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants