Skip to content

Commit c2fb7d2

Browse files
committedNov 6, 2024
Fix build artifact names
·
v8.1.0v7.7.1
1 parent 81e1bb1 commit c2fb7d2

File tree

2 files changed

+74
-88
lines changed

2 files changed

+74
-88
lines changed
 

‎README.md

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,36 +24,28 @@ npm i react-querybuilder @react-querybuilder/chakra @chakra-ui/icons @chakra-ui/
2424
To configure the query builder to use Chakra-compatible components, place `QueryBuilderChakra` above `QueryBuilder` and beneath `ChakraProvider` in the component hierarchy.
2525

2626
```tsx
27-
import { ChakraProvider, extendTheme } from "@chakra-ui/react";
28-
import { QueryBuilderChakra } from "@react-querybuilder/chakra";
29-
import { useState } from "react";
30-
import {
31-
type Field,
32-
QueryBuilder,
33-
type RuleGroupType,
34-
} from "react-querybuilder";
27+
import { ChakraProvider, extendTheme } from '@chakra-ui/react';
28+
import { QueryBuilderChakra } from '@react-querybuilder/chakra';
29+
import { useState } from 'react';
30+
import { type Field, QueryBuilder, type RuleGroupType } from 'react-querybuilder';
3531

3632
const chakraTheme = extendTheme();
3733

3834
const fields: Field[] = [
39-
{ name: "firstName", label: "First Name" },
40-
{ name: "lastName", label: "Last Name" },
35+
{ name: 'firstName', label: 'First Name' },
36+
{ name: 'lastName', label: 'Last Name' },
4137
];
4238

4339
export function App() {
4440
const [query, setQuery] = useState<RuleGroupType>({
45-
combinator: "and",
41+
combinator: 'and',
4642
rules: [],
4743
});
4844

4945
return (
5046
<ChakraProvider theme={chakraTheme}>
5147
<QueryBuilderChakra>
52-
<QueryBuilder
53-
fields={fields}
54-
defaultQuery={query}
55-
onQueryChange={setQuery}
56-
/>
48+
<QueryBuilder fields={fields} defaultQuery={query} onQueryChange={setQuery} />
5749
</QueryBuilderChakra>
5850
</ChakraProvider>
5951
);

‎tsup.config.ts

Lines changed: 66 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { isolatedDeclaration } from 'oxc-transform';
44
import type { Options } from 'tsup';
55
import { defineConfig } from 'tsup';
66

7+
const pkgName = 'react-querybuilder_chakra2';
8+
79
const generateDTS = async (projDir: string): Promise<void> => {
810
const g = new Bun.Glob('**/*.{ts,tsx}');
911

@@ -56,81 +58,73 @@ const generateDTS = async (projDir: string): Promise<void> => {
5658
console.log(`${fileCount} DTS files generated.`);
5759
};
5860

59-
const getCjsIndexWriter = (pkgName: string, debug?: boolean) => async (): Promise<void> => {
60-
await writeFile(
61-
`dist/cjs/${debug ? 'debug' : 'index'}.js`,
62-
`'use strict';
61+
export default defineConfig(async options => {
62+
const entryPoint = `src/index.tsx`;
63+
64+
const commonOptions = {
65+
entry: { [pkgName]: entryPoint },
66+
sourcemap: true,
67+
...options,
68+
} satisfies Options;
69+
70+
const productionOptions = {
71+
minify: true,
72+
replaceNodeEnv: true,
73+
} satisfies Options;
74+
75+
const opts: Options[] = [
76+
// ESM, standard bundler dev, embedded `process` references
77+
{
78+
...commonOptions,
79+
format: 'esm',
80+
clean: true,
81+
onSuccess: () => generateDTS(import.meta.dir),
82+
},
83+
// ESM, Webpack 4 support. Target ES2017 syntax to compile away optional chaining and spreads
84+
{
85+
...commonOptions,
86+
entry: { [`${pkgName}.legacy-esm`]: entryPoint },
87+
// ESBuild outputs `'.mjs'` by default for the 'esm' format. Force '.js'
88+
outExtension: () => ({ js: '.js' }),
89+
target: 'es2017',
90+
format: 'esm',
91+
},
92+
// ESM for use in browsers. Minified, with `process` compiled away
93+
{
94+
...commonOptions,
95+
...productionOptions,
96+
entry: { [`${pkgName}.production`]: entryPoint },
97+
format: 'esm',
98+
outExtension: () => ({ js: '.mjs' }),
99+
},
100+
// CJS development
101+
{
102+
...commonOptions,
103+
entry: { [`${pkgName}.cjs.development`]: entryPoint },
104+
format: 'cjs',
105+
outDir: './dist/cjs/',
106+
},
107+
// CJS production
108+
{
109+
...commonOptions,
110+
...productionOptions,
111+
entry: { [`${pkgName}.cjs.production`]: entryPoint },
112+
format: 'cjs',
113+
outDir: './dist/cjs/',
114+
onSuccess: async () => {
115+
await writeFile(
116+
`dist/cjs/index.js`,
117+
`'use strict';
63118
if (process.env.NODE_ENV === 'production') {
64-
module.exports = require('./${pkgName}.cjs.production${debug ? '.debug' : ''}.js');
119+
module.exports = require('./${pkgName}.cjs.production.js');
65120
} else {
66-
module.exports = require('./${pkgName}.cjs.development${debug ? '.debug' : ''}.js');
121+
module.exports = require('./${pkgName}.cjs.development.js');
67122
}
68123
`
69-
);
70-
};
71-
72-
const tsupCommonConfig = (sourceDir: string) =>
73-
(async options => {
74-
const pkgName = `react-querybuilder${sourceDir.endsWith('react-querybuilder') ? '' : `_${sourceDir.split('/').pop()}`}`;
75-
const x = (await Bun.file(path.join(sourceDir + '/src/index.tsx')).exists()) ? 'x' : '';
76-
const entryPoint = `src/index.ts${x}`;
77-
78-
const commonOptions = {
79-
entry: { [pkgName]: entryPoint },
80-
sourcemap: true,
81-
esbuildPlugins: [],
82-
...options,
83-
} satisfies Options;
84-
85-
const productionOptions = {
86-
minify: true,
87-
replaceNodeEnv: true,
88-
} satisfies Options;
89-
90-
const opts: Options[] = [
91-
// ESM, standard bundler dev, embedded `process` references
92-
{
93-
...commonOptions,
94-
format: 'esm',
95-
clean: true,
96-
onSuccess: () => generateDTS(sourceDir),
124+
);
97125
},
98-
// ESM, Webpack 4 support. Target ES2017 syntax to compile away optional chaining and spreads
99-
{
100-
...commonOptions,
101-
entry: { [`${pkgName}.legacy-esm`]: entryPoint },
102-
// ESBuild outputs `'.mjs'` by default for the 'esm' format. Force '.js'
103-
outExtension: () => ({ js: '.js' }),
104-
target: 'es2017',
105-
format: 'esm',
106-
},
107-
// ESM for use in browsers. Minified, with `process` compiled away
108-
{
109-
...commonOptions,
110-
...productionOptions,
111-
entry: { [`${pkgName}.production`]: entryPoint },
112-
format: 'esm',
113-
outExtension: () => ({ js: '.mjs' }),
114-
},
115-
// CJS development
116-
{
117-
...commonOptions,
118-
entry: { [`${pkgName}.cjs.development`]: entryPoint },
119-
format: 'cjs',
120-
outDir: './dist/cjs/',
121-
},
122-
// CJS production
123-
{
124-
...commonOptions,
125-
...productionOptions,
126-
entry: { [`${pkgName}.cjs.production`]: entryPoint },
127-
format: 'cjs',
128-
outDir: './dist/cjs/',
129-
onSuccess: getCjsIndexWriter(pkgName, false),
130-
},
131-
];
132-
133-
return opts;
134-
}) as (options: Options) => Promise<Options[]>;
126+
},
127+
];
135128

136-
export default defineConfig(tsupCommonConfig(import.meta.dir));
129+
return opts;
130+
});

0 commit comments

Comments
 (0)
Please sign in to comment.