Skip to content

Commit 1a8913a

Browse files
authored
Add exports field in package.json (#11)
1 parent 822fdfd commit 1a8913a

File tree

13 files changed

+535
-354
lines changed

13 files changed

+535
-354
lines changed

apps/docs/components/playground/preview.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,14 @@ export function Preview({ lang, value, theme, options }: PreviewProps) {
5656
<RoughSVG className="flex-1" options={options}>
5757
<p className="my-4">Output Preview:</p>
5858
<div ref={previewRef}>
59-
{lang === 'jsx' ? (
60-
// @ts-expect-error react version
61-
<JSXParser jsx={value} />
62-
) : (
63-
<SVG src={value} key={optionsID} />
64-
)}
59+
{lang === 'jsx'
60+
? (
61+
// @ts-expect-error react version
62+
<JSXParser jsx={value} />
63+
)
64+
: (
65+
<SVG src={value} key={optionsID} />
66+
)}
6567
</div>
6668
</RoughSVG>
6769
</div>

packages/react-rough-fiber/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-rough-fiber",
3-
"version": "0.0.6",
3+
"version": "0.0.7",
44
"description": "A React renderer for rendering hand-drawn SVGs.",
55
"author": "Bowen <zwxdyx@foxmail.com>(https://github.com/Bowen7)",
66
"license": "MIT",
@@ -32,8 +32,8 @@
3232
"lint": "eslint *.ts*",
3333
"test": "vitest",
3434
"build": "rm -rf dist && tsup",
35-
"pre-publish": "node scripts/pre-publish.js && npm run build",
36-
"publish-next": "node scripts/pre-next-publish.js && npm run build && npm publish --tag next --access public && node scripts/post-next-publish.js"
35+
"pre-publish": "node scripts/pre-publish.mjs && npm run build",
36+
"publish-next": "node scripts/pre-next-publish.mjs && npm run build && npm publish --tag next --access public && node scripts/post-next-publish.mjs"
3737
},
3838
"peerDependencies": {
3939
"react": ">=17.0.0",
@@ -63,7 +63,7 @@
6363
"regenerator-runtime": "^0.13.11",
6464
"roughjs": "4.5.2",
6565
"tsconfig": "workspace:*",
66-
"tsup": "^6.7.0",
66+
"tsup": "^8.4.0",
6767
"typescript": "^4.5.2",
6868
"vitest": "^2.1.8"
6969
}

packages/react-rough-fiber/scripts/post-next-publish.js

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import fs from 'node:fs'
2+
import path, { dirname } from 'node:path'
3+
import { fileURLToPath } from 'node:url'
4+
5+
const __filename = fileURLToPath(import.meta.url)
6+
const __dirname = dirname(__filename)
7+
8+
const packagePath = path.join(__dirname, '../package.json')
9+
const packageJSON = JSON.parse(fs.readFileSync(packagePath, 'utf8').toString())
10+
11+
packageJSON.main = './src/index.tsx'
12+
delete packageJSON.types
13+
delete packageJSON.module
14+
delete packageJSON.exports
15+
packageJSON.version = packageJSON.version.split('-')[0]
16+
17+
fs.writeFileSync(packagePath, `${JSON.stringify(packageJSON, null, 2)}\n`)

packages/react-rough-fiber/scripts/pre-next-publish.js

Lines changed: 0 additions & 18 deletions
This file was deleted.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import fs from 'node:fs'
2+
import path, { dirname } from 'node:path'
3+
import { fileURLToPath } from 'node:url'
4+
import { Repository } from '@napi-rs/simple-git'
5+
import { addFieldsIntoPackageJSON } from './utils.mjs'
6+
7+
const __filename = fileURLToPath(import.meta.url)
8+
const __dirname = dirname(__filename)
9+
10+
const repo = new Repository(path.resolve(__dirname, '../../../'))
11+
const headReference = repo.head()
12+
const shortSHA = headReference.target().slice(0, 7)
13+
const packagePath = path.join(__dirname, '../package.json')
14+
const packageJSON = JSON.parse(fs.readFileSync(packagePath, 'utf8').toString())
15+
16+
addFieldsIntoPackageJSON(packageJSON)
17+
18+
const version = packageJSON.version
19+
packageJSON.version = `${version}-experimental-${shortSHA}`
20+
21+
fs.writeFileSync(packagePath, JSON.stringify(packageJSON, null, 2))

packages/react-rough-fiber/scripts/pre-publish.js

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import fs from 'node:fs'
2+
import path, { dirname } from 'node:path'
3+
import { fileURLToPath } from 'node:url'
4+
import { addFieldsIntoPackageJSON } from './utils.mjs'
5+
6+
const __filename = fileURLToPath(import.meta.url)
7+
const __dirname = dirname(__filename)
8+
9+
const packagePath = path.join(__dirname, '../package.json')
10+
const packageJSON = JSON.parse(fs.readFileSync(packagePath, 'utf8').toString())
11+
12+
addFieldsIntoPackageJSON(packageJSON)
13+
14+
fs.writeFileSync(packagePath, JSON.stringify(packageJSON, null, 2))
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
export function addFieldsIntoPackageJSON(packageJson) {
2+
packageJson.main = './dist/index.js'
3+
packageJson.types = './dist/index.d.ts'
4+
packageJson.module = './dist/index.mjs'
5+
packageJson.exports = {
6+
'.': {
7+
require: {
8+
types: './dist/index.d.ts',
9+
default: './dist/index.js',
10+
},
11+
default: {
12+
types: './dist/index.d.mts',
13+
default: './dist/index.mjs',
14+
},
15+
},
16+
}
17+
}

packages/react-rough-fiber/src/renderer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import type {
88
Options,
99
} from './types'
1010
import Reconciler from 'react-reconciler'
11-
import * as ReactReconcilerConstants from 'react-reconciler/constants'
11+
import * as ReactReconcilerConstants from 'react-reconciler/constants.js'
1212
import {
1313
DATA_RRF_GROUP,
1414
HTML_NAMESPACE,

packages/react-rough-fiber/src/roughSVG.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Options, RoughSVGProps } from './types'
22
import { createElement, useEffect, useRef, useState } from 'react'
3-
import { LegacyRoot } from 'react-reconciler/constants'
3+
import { LegacyRoot } from 'react-reconciler/constants.js'
44
import { createReconciler } from './renderer'
55

66
export function RoughSVG({

packages/react-rough-fiber/tsup.config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,4 @@ export default defineConfig({
88
dts: true,
99
format: ['esm', 'cjs'],
1010
platform: 'browser',
11-
legacyOutput: true,
1211
});

0 commit comments

Comments
 (0)