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: implement syntax #35

Merged
merged 1 commit into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
dist
compiled
doc_build

# ignore all JS/TS files, use Biome
**/*[.js,.ts,.jsx,.tsx.json,.json5]
21 changes: 21 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,26 @@
"mdx.validate.validateFileLinks": "ignore",
"editor.codeActionsOnSave": {
"source.organizeImports.biome": "explicit"
},
"[javascript]": {
"editor.defaultFormatter": "biomejs.biome"
},
"[javascriptreact]": {
"editor.defaultFormatter": "biomejs.biome"
},
"[json5]": {
"editor.defaultFormatter": "biomejs.biome"
},
"[json]": {
"editor.defaultFormatter": "biomejs.biome"
},
"[jsonc]": {
"editor.defaultFormatter": "biomejs.biome"
},
"[typescript]": {
"editor.defaultFormatter": "biomejs.biome"
},
"[typescriptreact]": {
"editor.defaultFormatter": "biomejs.biome"
}
}
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ The project is still under development, so it possible dependents on unstable Rs

Current unstable versions are:

| Package | Version | Link |
| ------------ | ------------------------------------------------------- | ------------------------------------------------------- |
| @rspack/core | @rspack/core-canary@1.0.0-canary-26460a2-20240710092718 | [PR](https://github.com/web-infra-dev/rspack/pull/7102) |
<!-- | Package | Version | Link |
| ------------ | ------------------------------------------------------- | --------------------------------------------------------- |
| @rspack/core | @rspack/[email protected]0b368b6-20240704171208 | [PR](https://github.com/webpack/webpack/pull/11751/files) | -->
5 changes: 0 additions & 5 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@
"quoteStyle": "single"
}
},
"json": {
"formatter": {
"enabled": false
}
},
"linter": {
"enabled": true,
"ignore": ["./e2e/cases/**/*/src/*"],
Expand Down
4 changes: 2 additions & 2 deletions e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Rslib will try to cover the common scenarios in the [integration test cases of M
| jsx | ⚪️ | |
| metafile | ⚪️ | |
| minify | ⚪️ | |
| platform | ⚪️ | |
| platform | 🟢 | |
| redirect | ⚪️ | |
| resolve | ⚪️ | |
| shims | ⚪️ | |
Expand All @@ -37,7 +37,7 @@ Rslib will try to cover the common scenarios in the [integration test cases of M
| sourceMap | ⚪️ | |
| splitting | ⚪️ | |
| style | ⚪️ | |
| target | ⚪️ | |
| target | 🟢 | |
| transformImport | ⚪️ | |
| transformLodash | ⚪️ | |
| tsconfig | ⚪️ | |
Expand Down
4 changes: 2 additions & 2 deletions e2e/cases/alias/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`alias should work 1`] = `
exports[`source.alias 1`] = `
"
;// CONCATENATED MODULE: ./e2e/cases/alias/src/a.ts
const a = 'hello world';
Expand All @@ -13,7 +13,7 @@ export { a };
"
`;

exports[`alias should work 2`] = `
exports[`source.alias 2`] = `
"(() => { // webpackBootstrap
"use strict";
var __webpack_exports__ = {};
Expand Down
2 changes: 1 addition & 1 deletion e2e/cases/alias/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect, test } from 'vitest';
import { buildAndGetEntryJsResults } from '#shared';

test('alias should work', async () => {
test('source.alias', async () => {
const fixturePath = __dirname;
const { contents } = await buildAndGetEntryJsResults(fixturePath);

Expand Down
2 changes: 1 addition & 1 deletion e2e/cases/define/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect, test } from 'vitest';
import { buildAndGetEntryJsResults } from '#shared';

test('define should work', async () => {
test('source.define', async () => {
const fixturePath = __dirname;
const { contents } = await buildAndGetEntryJsResults(fixturePath);

Expand Down
2 changes: 1 addition & 1 deletion e2e/cases/externals/browser/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { join } from 'node:path';
import { expect, test } from 'vitest';
import { buildAndGetEntryJsResults } from '#shared';

test('should fail when platform is not "node"', async () => {
test('should fail to build when `output.target` is not "node"', async () => {
const fixturePath = join(__dirname);
const build = buildAndGetEntryJsResults(fixturePath);
await expect(build).rejects.toThrowError('Rspack build failed!');
Expand Down
2 changes: 1 addition & 1 deletion e2e/cases/externals/node/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { join } from 'node:path';
import { expect, test } from 'vitest';
import { buildAndGetEntryJsResults } from '#shared';

test('auto externalize Node.js built-in modules when platform is "node"', async () => {
test('auto externalize Node.js built-in modules when `output.target` is "node"', async () => {
const fixturePath = join(__dirname);
const { contents } = await buildAndGetEntryJsResults(fixturePath);

Expand Down
48 changes: 48 additions & 0 deletions e2e/cases/syntax/config/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`should downgrade class private method by default 1`] = `
"
;// CONCATENATED MODULE: ./node_modules/.pnpm/@[email protected]/node_modules/@swc/helpers/esm/_class_private_method_get.js
function _class_private_method_get(receiver, privateSet, fn) {
if (!privateSet.has(receiver)) throw new TypeError("attempted to get private field on non-instance");
return fn;
}
;// CONCATENATED MODULE: ./node_modules/.pnpm/@[email protected]/node_modules/@swc/helpers/esm/_check_private_redeclaration.js
function _check_private_redeclaration(obj, privateCollection) {
if (privateCollection.has(obj)) {
throw new TypeError("Cannot initialize the same private elements twice on an object");
}
}
;// CONCATENATED MODULE: ./node_modules/.pnpm/@[email protected]/node_modules/@swc/helpers/esm/_class_private_method_init.js
function _class_private_method_init(obj, privateSet) {
_check_private_redeclaration(obj, privateSet);
privateSet.add(obj);
}
;// CONCATENATED MODULE: ./e2e/cases/syntax/config/src/foo.ts
var _bar = new WeakSet();
class Foo {
constructor(){
_class_private_method_init(this, _bar);
_class_private_method_get(this, _bar, bar).call(this);
}
}
function bar() {}
/*#__PURE__*/
;// CONCATENATED MODULE: ./e2e/cases/syntax/config/src/index.ts
export { Foo };
"
`;
12 changes: 12 additions & 0 deletions e2e/cases/syntax/config/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { expect, test } from 'vitest';
import { buildAndGetEntryJsResults } from '#shared';

test('should downgrade class private method by default', async () => {
const fixturePath = __dirname;
const { contents } = await buildAndGetEntryJsResults(fixturePath);

expect(contents.esm).toMatchSnapshot();
expect(contents.esm).not.toContain('#bar');

expect(contents.cjs).toContain('#bar');
});
23 changes: 23 additions & 0 deletions e2e/cases/syntax/config/rslib.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { join } from 'node:path';
import { defineConfig } from '@rslib/core';
import { generateBundleCjsConfig, generateBundleEsmConfig } from '#shared';

export default defineConfig({
lib: [
generateBundleEsmConfig(__dirname, {
output: {
syntax: 'es2015',
},
}),
generateBundleCjsConfig(__dirname, {
output: {
syntax: ['node 20'],
},
}),
],
source: {
entry: {
main: join(__dirname, 'src/index.ts'),
},
},
});
9 changes: 9 additions & 0 deletions e2e/cases/syntax/config/src/foo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class Foo {
constructor() {
this.#bar();
}

#bar() {}
}

export { Foo };
1 change: 1 addition & 0 deletions e2e/cases/syntax/config/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { Foo } from './foo';
10 changes: 10 additions & 0 deletions e2e/cases/syntax/config/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "@rslib/tsconfig/base",
"compilerOptions": {
"baseUrl": "./",
"paths": {
"@src/*": ["./src/*"]
}
},
"include": ["src"]
}
19 changes: 19 additions & 0 deletions e2e/cases/syntax/default/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`should downgrade class private method by default 1`] = `
"
;// CONCATENATED MODULE: ./e2e/cases/syntax/default/src/foo.ts
class Foo {
constructor(){
this.#bar();
}
#bar() {}
}
;// CONCATENATED MODULE: ./e2e/cases/syntax/default/src/index.ts
export { Foo };
"
`;
12 changes: 12 additions & 0 deletions e2e/cases/syntax/default/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { expect, test } from 'vitest';
import { buildAndGetEntryJsResults } from '#shared';

test('should downgrade class private method by default', async () => {
const fixturePath = __dirname;
const { contents } = await buildAndGetEntryJsResults(fixturePath);

expect(contents.esm).toMatchSnapshot();
expect(contents.esm).toContain('#bar');

expect(contents.cjs).toContain('#bar');
});
12 changes: 12 additions & 0 deletions e2e/cases/syntax/default/rslib.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { join } from 'node:path';
import { defineConfig } from '@rslib/core';
import { generateBundleCjsConfig, generateBundleEsmConfig } from '#shared';

export default defineConfig({
lib: [generateBundleEsmConfig(__dirname), generateBundleCjsConfig(__dirname)],
source: {
entry: {
main: join(__dirname, 'src/index.ts'),
},
},
});
9 changes: 9 additions & 0 deletions e2e/cases/syntax/default/src/foo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class Foo {
constructor() {
this.#bar();
}

#bar() {}
}

export { Foo };
1 change: 1 addition & 0 deletions e2e/cases/syntax/default/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { Foo } from './foo';
10 changes: 10 additions & 0 deletions e2e/cases/syntax/default/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "@rslib/tsconfig/base",
"compilerOptions": {
"baseUrl": "./",
"paths": {
"@src/*": ["./src/*"]
}
},
"include": ["src"]
}
4 changes: 2 additions & 2 deletions e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
},
"devDependencies": {
"@playwright/test": "1.43.1",
"@rsbuild/core": "1.0.0-alpha.3",
"@rsbuild/core": "1.0.0-alpha.9",
"@rslib/core": "workspace:*",
"@rslib/tsconfig": "workspace:*",
"@types/fs-extra": "^11.0.4",
"@types/node": "18.x",
"@types/node": "~18.19.39",
"@types/react": "^18.3.3",
"fast-glob": "^3.3.2",
"fs-extra": "^11.2.0"
Expand Down
19 changes: 8 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"build:examples": "cross-env NX_DAEMON=false nx run-many -t build --projects @examples/* --parallel=10",
"check-dependency-version": "check-dependency-version-consistency .",
"check-spell": "npx cspell",
"lint": "biome check . --diagnostic-level=warn && pnpm run check-spell",
"lint": "biome check . --diagnostic-level=warn && pnpm run check-spell",
"prebundle": "nx run-many -t prebundle",
"prepare": "pnpm run build && simple-git-hooks",
"sort-package-json": "npx sort-package-json \"packages/*/package.json\"",
Expand All @@ -20,27 +20,24 @@
"pre-commit": "npx nano-staged"
},
"nano-staged": {
"*.{md,mdx,json,css,less,scss}": "prettier --write",
"*.{js,jsx,ts,tsx,mjs,cjs}": [
"biome check --apply --formatter-enabled=false --linter-enabled=false",
"prettier --write"
],
"*.{md,mdx,css,less,scss}": "prettier --write",
"*.{js,jsx,ts,tsx,mjs,cjs,json,jsonc,json5}": ["biome check --write"],
"package.json": "pnpm run check-dependency-version"
},
"devDependencies": {
"@biomejs/biome": "^1.8.1",
"@modern-js/module-tools": "^2.53.0",
"@biomejs/biome": "^1.8.3",
"@modern-js/module-tools": "^2.55.0",
"@types/fs-extra": "^11.0.4",
"check-dependency-version-consistency": "^4.1.0",
"cross-env": "^7.0.3",
"cspell-ban-words": "^0.0.3",
"fs-extra": "^11.2.0",
"nano-staged": "^0.8.0",
"nx": "^19.3.0",
"nx": "^19.4.2",
"prettier": "^3.3.2",
"prettier-plugin-packagejson": "^2.5.0",
"simple-git-hooks": "^2.11.1",
"typescript": "^5.4.5",
"typescript": "^5.5.3",
"vitest": "^1.6.0"
},
"packageManager": "[email protected]",
Expand All @@ -50,7 +47,7 @@
},
"pnpm": {
"overrides": {
"@rspack/core": "npm:@rspack/core-canary@1.0.0-canary-26460a2-20240710092718"
"@rspack/core": "1.0.0-alpha.3"
}
}
}
Loading
Loading