Skip to content

Commit

Permalink
Bump scaffold (#38)
Browse files Browse the repository at this point in the history
* Bump scaffold

* Fix JSX

* Converge declarationDir

---------

Co-authored-by: @compulim <@compulim>
Co-authored-by: William Wong <compulim@hotmail.com>
  • Loading branch information
compulim-workflow-bot[bot] and compulim authored Oct 9, 2023
1 parent bdc36be commit 67db418
Show file tree
Hide file tree
Showing 21 changed files with 143 additions and 39 deletions.
1 change: 1 addition & 0 deletions .eslintrc.jest.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
env:
commonjs: true
es2021: true
es2022: true
jest: true
Expand Down
1 change: 1 addition & 0 deletions .eslintrc.react.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
extends:
- plugin:react/recommended
- plugin:react/jsx-runtime
plugins:
- react
settings:
Expand Down
7 changes: 6 additions & 1 deletion packages/integration-test/babel.config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
{
"presets": [
"@babel/preset-react",
[
"@babel/preset-react",
{
"runtime": "automatic"
}
],
[
"@babel/preset-env",
{
Expand Down
16 changes: 14 additions & 2 deletions packages/integration-test/jest.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,26 @@
"\\.cjsx?$": [
"babel-jest",
{
"presets": ["@babel/preset-react"]
"presets": [
[
"@babel/preset-react",
{
"runtime": "automatic"
}
]
]
}
],
"\\.mjsx?$": [
"babel-jest",
{
"presets": [
"@babel/preset-react",
[
"@babel/preset-react",
{
"runtime": "automatic"
}
],
[
"@babel/preset-env",
{
Expand Down
6 changes: 6 additions & 0 deletions packages/integration-test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// This configuration file is for VSCode only.
{
"compilerOptions": {
"jsx": "react-jsx"
}
}
2 changes: 1 addition & 1 deletion packages/pages/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.0.0-0",
"description": "",
"scripts": {
"build": "esbuild --bundle --entry-names=[name]/[ext]/main --minify --outdir=./public/static/ --sourcemap app=./src/app/index.tsx",
"build": "esbuild --bundle --entry-names=[name]/[ext]/main --jsx=automatic --minify --outdir=./public/static/ --sourcemap app=./src/app/index.tsx",
"bump": "npm run bump:prod && npm run bump:dev && npm run bump:auditfix",
"bump:auditfix": "npm audit fix || exit 0",
"bump:dev": "PACKAGES_TO_BUMP=$(cat package.json | jq -r '.localPeerDependencies // {} as $L | .devDependencies // {} | to_entries | map(select(.key as $K | $L | has($K) | not)) | map(.key + \"@latest\") | join(\" \")') && [ ! -z \"$PACKAGES_TO_BUMP\" ] && npm install $PACKAGES_TO_BUMP || true",
Expand Down
2 changes: 1 addition & 1 deletion packages/pages/src/app/App.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Fragment } from 'react';
import { useRefFrom } from 'use-ref-from';
import React, { Fragment } from 'react';

const App = () => {
const value = useRefFrom('Hello, World!');
Expand Down
1 change: 0 additions & 1 deletion packages/pages/src/app/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { createRoot } from 'react-dom/client';
import React from 'react';

import App from './App';

Expand Down
2 changes: 1 addition & 1 deletion packages/pages/src/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"esModuleInterop": true,
"jsx": "react",
"jsx": "react-jsx",
"lib": ["DOM", "ESNext", "WebWorker"],
"moduleResolution": "Bundler",
"noEmit": true,
Expand Down
61 changes: 49 additions & 12 deletions packages/use-ref-from/__tests__/__setup__/typingTestTransformer.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
// Notes: to test changes in this file, run "jest" with "--no-cache" argument.

const run = ({ filename }) => {
const fs = require('fs/promises');
const { extname } = require('path');
const typeScript = require('typescript');

function compile(...filenames) {
const program = typeScript.createProgram(filenames, {
allowSyntheticDefaultImports: true,
jsx: typeScript.JsxEmit.React,
noEmit: true,
skipLibCheck: true,
strict: true
});
const TS_EXPECT_ERROR = /(\/\/\s+)(@ts-expect-error)[\s+(.*)]/gu;
const TSCONFIG = {
allowSyntheticDefaultImports: true,
jsx: typeScript.JsxEmit.React,
noEmit: true,
skipLibCheck: true,
strict: true
};

async function compile(filename) {
const program = typeScript.createProgram([filename], TSCONFIG);

const emitResult = program.emit();
const allDiagnostics = typeScript.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
Expand All @@ -27,11 +32,43 @@ const run = ({ filename }) => {
});
}

if (filename.includes('fail')) {
test(`Compile ${filename} should fail`, () => expect(() => compile(filename)).toThrow());
} else {
test(`Compile ${filename} should succeed`, () => compile(filename));
async function checkExpectError(filename) {
const sourceText = await fs.readFile(filename, 'utf-8');
const sourceTextWithoutExpectError = sourceText.replace(TS_EXPECT_ERROR, '$1');

const extension = extname(filename);
const tempFilename = filename.substring(0, filename.length - extension.length) + `.tmp${extension}`;

await fs.writeFile(tempFilename, sourceTextWithoutExpectError);

try {
const program = typeScript.createProgram([tempFilename], TSCONFIG);

const emitResult = program.emit();
const allDiagnostics = typeScript.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);

allDiagnostics.forEach(({ file, messageText, start }) => {
if (file && start) {
const { line } = file.getLineAndCharacterOfPosition(start);
const message = typeScript.flattenDiagnosticMessageText(messageText, '\n');

const expectedErrorLine = file.getFullText().split('\n')[line - 1];
const expectedError = expectedErrorLine?.replace(/\s*\/\/\s+/u, '').trim();

expect(message).toEqual(expect.stringContaining(expectedError));
} else {
throw new Error(typeScript.flattenDiagnosticMessageText(messageText, '\n'));
}
});
} finally {
fs.unlink(tempFilename);
}
}

describe(filename, () => {
test('should succeed', () => compile(filename));
test('should have @ts-expect-error describing compile errors correctly', () => checkExpectError(filename));
});
};

module.exports = {
Expand Down
1 change: 1 addition & 0 deletions packages/use-ref-from/__tests__/types/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.tmp.tsx
14 changes: 12 additions & 2 deletions packages/use-ref-from/babel.commonjs.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,18 @@
]
],
"presets": [
"@babel/preset-react",
"@babel/preset-typescript",
[
"@babel/preset-react",
{
"runtime": "automatic"
}
],
[
"@babel/preset-typescript",
{
"allowDeclareFields": true
}
],
[
"@babel/preset-env",
{
Expand Down
14 changes: 12 additions & 2 deletions packages/use-ref-from/babel.esmodules.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,18 @@
]
],
"presets": [
"@babel/preset-react",
"@babel/preset-typescript",
[
"@babel/preset-react",
{
"runtime": "automatic"
}
],
[
"@babel/preset-typescript",
{
"allowDeclareFields": true
}
],
[
"@babel/preset-env",
{
Expand Down
19 changes: 15 additions & 4 deletions packages/use-ref-from/jest.config.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
{
"testPathIgnorePatterns": ["/__tests__/__setup__/", "/lib/", "/node_modules/", "/__types__/", "\\.pnp\\.[^\\/]+$"],
"testPathIgnorePatterns": ["/__setup__/", "/lib/", "/node_modules/", "/__types__/", "\\.pnp\\.[^\\/]+$"],
"transform": {
"/__tests__/types/": ["<rootDir>/__tests__/__setup__/typingTestTransformer.js"],
"\\.[jt]sx?$": [
"babel-jest",
{
"presets": [
"@babel/preset-react",
"@babel/preset-typescript",
[
"@babel/preset-react",
{
"runtime": "automatic"
}
],
[
"@babel/preset-typescript",
{
"allowDeclareFields": true
}
],
[
"@babel/preset-env",
{
Expand All @@ -21,5 +31,6 @@
"sourceMaps": true
}
]
}
},
"watchPathIgnorePatterns": ["\\.tmp\\."]
}
11 changes: 5 additions & 6 deletions packages/use-ref-from/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,27 @@
"exports": {
".": {
"import": {
"types": "./lib/esmodules-types/index.d.ts",
"types": "./lib/esmodules/index.d.ts",
"default": "./lib/esmodules/index.js"
},
"require": {
"types": "./lib/commonjs-types/index.d.ts",
"types": "./lib/commonjs/index.d.ts",
"default": "./lib/commonjs/index.js"
}
},
"./useRefFrom": {
"import": {
"types": "./lib/esmodules-types/useRefFrom.d.ts",
"types": "./lib/esmodules/useRefFrom.d.ts",
"default": "./lib/esmodules/useRefFrom.js"
},
"require": {
"types": "./lib/commonjs-types/useRefFrom.d.ts",
"types": "./lib/commonjs/useRefFrom.d.ts",
"default": "./lib/commonjs/useRefFrom.js"
}
}
},
"main": "./lib/commonjs/index.js",
"typings": "./lib/commonjs-types/index.d.ts",
"typings": "./lib/commonjs/index.d.ts",
"scripts": {
"build": "npm run build:babel:commonjs && npm run build:babel:esmodules && npm run build:typescript:commonjs && npm run build:typescript:esmodules",
"build:babel:commonjs": "babel src --config-file ./babel.commonjs.config.json --extensions .ts,.tsx --out-dir ./lib/commonjs/",
Expand All @@ -48,7 +48,6 @@
"precommit:typescript:production": "tsc --noEmit --project ./src/tsconfig.precommit.production.json",
"precommit:typescript:test": "tsc --noEmit --project ./src/tsconfig.precommit.test.json",
"prepack": "cp ../../CHANGELOG.md . && cp ../../LICENSE . && cp ../../README.md .",
"start": "esbuild --bundle --outfile=./public/main.js --servedir=./public --sourcemap ./scenarios/index.jsx",
"test": "jest"
},
"repository": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"declarationDir": "../lib/commonjs-types/",
"declarationDir": "../lib/commonjs/",
"module": "CommonJS",
"moduleResolution": "Node10"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"declarationDir": "../lib/esmodules-types/",
"declarationDir": "../lib/esmodules/",
"module": "ESNext",
"moduleResolution": "Bundler"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/use-ref-from/src/tsconfig.declaration.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"declaration": true,
"emitDeclarationOnly": true,
"esModuleInterop": true,
"jsx": "react",
"jsx": "react-jsx",
"noEmit": false
},
"exclude": ["**/*.spec.*", "**/*.test.*", "__test__/**/*"],
"exclude": ["**/*.spec.*", "**/*.test.*", "__tests__/**/*"],
"extends": "@tsconfig/strictest/tsconfig.json"
}
12 changes: 12 additions & 0 deletions packages/use-ref-from/src/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// This configuration file is for VSCode only.
{
"compilerOptions": {
"esModuleInterop": true,
"jsx": "react-jsx",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"noEmit": true,
"strict": true
},
"extends": "@tsconfig/strictest/tsconfig.json"
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"esModuleInterop": true,
"jsx": "react",
"jsx": "react-jsx",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"noEmit": true,
Expand Down
2 changes: 1 addition & 1 deletion packages/use-ref-from/src/tsconfig.precommit.test.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"esModuleInterop": true,
"jsx": "react",
"jsx": "react-jsx",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"noEmit": true,
Expand Down

0 comments on commit 67db418

Please sign in to comment.