Skip to content

Use Git revision in version and add Node CI examples #3258

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

Merged
merged 3 commits into from
Mar 13, 2023
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
15 changes: 14 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ jobs:
- name: Install deps
run: yarn install

# Read existing version, reuse that, add a Git short hash
- name: Set build version to Git commit
run: node scripts/writeGitVersion.js $(git rev-parse --short HEAD)

- name: Check updated version
run: jq .version package.json

- name: Pack
run: yarn pack

Expand Down Expand Up @@ -123,6 +130,9 @@ jobs:
- name: Install build artifact
run: yarn add ./package.tgz

- name: Show installed RTK versions
run: yarn info @reduxjs/toolkit

- run: sed -i -e /@remap-prod-remove-line/d ./tsconfig.base.json ./jest.config.js ./src/tests/*.* ./src/query/tests/*.*

- name: Test types
Expand All @@ -139,7 +149,7 @@ jobs:
fail-fast: false
matrix:
node: ['16.x']
example: ['cra4', 'cra5', 'next', 'vite']
example: ['cra4', 'cra5', 'next', 'vite', 'node-standard', 'node-esm']
defaults:
run:
working-directory: ./examples/publish-ci/${{ matrix.example }}
Expand Down Expand Up @@ -170,6 +180,9 @@ jobs:
- name: Install RTK build artifact
run: yarn add ./package.tgz

- name: Show installed RTK versions
run: yarn info @reduxjs/toolkit

- name: Build example
run: yarn build

Expand Down
35 changes: 35 additions & 0 deletions examples/publish-ci/node-esm/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*

typesversions
.cache
.yarnrc
.yarn/*
!.yarn/patches
!.yarn/releases
!.yarn/plugins
!.yarn/sdks
!.yarn/versions
.pnp.*
*.tgz
19 changes: 19 additions & 0 deletions examples/publish-ci/node-esm/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "dual-module-test",
"version": "1.0.0",
"license": "MIT",
"type": "module",
"scripts": {
"build": "echo Done",
"test": "node test-cjs.cjs"
},
"dependencies": {
"@reduxjs/toolkit": "^1.9.3",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-redux": "^8.0.5"
},
"devDependencies": {
"resolve-esm": "^1.4.0"
}
}
45 changes: 45 additions & 0 deletions examples/publish-ci/node-esm/test-cjs.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const assert = require('node:assert')
const path = require('path')

const { createSlice } = require('@reduxjs/toolkit')
const { createApi: createApiPlain } = require('@reduxjs/toolkit/query')
const { createApi: createApiReact } = require('@reduxjs/toolkit/query/react')

console.log('Testing Node with CJS imports...')

function checkFunctionName(fn, name, category) {
console.log(`Checking ${category} '${name}' === '${fn.name}'`)
assert(
fn.name === name,
`${category} \`${name}\` did not import correctly (name: '${fn.name}')`
)
}

const entries = [
[createSlice, 'createSlice', 'Core'],
[createApiPlain, 'baseCreateApi', 'RTKQ core'],
[createApiReact, 'baseCreateApi', 'RTKQ React'],
]

for (let [fn, name, category] of entries) {
try {
checkFunctionName(fn, name, category)
} catch (error) {
console.error(error)
}
}

const moduleNames = [
['@reduxjs/toolkit', 'dist/index.js'],
['@reduxjs/toolkit/query', 'dist/query/index.js'],
['@reduxjs/toolkit/query/react', 'dist/query/react/index.js'],
]

for (let [moduleName, expectedFilename] of moduleNames) {
const modulePath = require.resolve(moduleName)
const posixPath = modulePath.split(path.sep).join(path.posix.sep)
console.log(`Module: ${moduleName}, path: ${posixPath}`)
assert(posixPath.endsWith(expectedFilename))
}

console.log('CJS test succeeded')
48 changes: 48 additions & 0 deletions examples/publish-ci/node-esm/test-esm.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// TODO This entire file doesn't work yet with RTK 1.9.3 master

import assert from 'node:assert'
import path from 'path'
import { importMetaResolve } from 'resolve-esm'

import { createSlice } from '@reduxjs/toolkit'
import { createApi as createApiPlain } from '@reduxjs/toolkit/query'
import { createApi as createApiReact } from '@reduxjs/toolkit/query/react'

console.log('Testing Node with ESM imports...')

function checkFunctionName(fn, name, category) {
console.log(`Checking ${category} '${name}' === '${fn.name}'`)
assert(
fn.name === name,
`${category} \`${name}\` did not import correctly (name: '${fn.name}')`
)
}

const entries = [
[createSlice, 'createSlice', 'Core'],
[createApiPlain, 'baseCreateApi', 'RTKQ core'],
[createApiReact, 'baseCreateApi', 'RTKQ React'],
]

for (let [fn, name, category] of entries) {
try {
checkFunctionName(fn, name, category)
} catch (error) {
console.error(error)
}
}

const moduleNames = [
['@reduxjs/toolkit', 'dist/index.js'],
['@reduxjs/toolkit/query', 'dist/query/index.js'],
['@reduxjs/toolkit/query/react', 'dist/query/react/index.js'],
]

;(async () => {
for (let [moduleName, expectedFilename] of moduleNames) {
const modulePath = await importMetaResolve(moduleName)
const posixPath = modulePath.split(path.sep).join(path.posix.sep)
console.log(`Module: ${moduleName}, path: ${posixPath}`)
assert(posixPath.endsWith(expectedFilename))
}
})()
Loading