Skip to content

Commit

Permalink
Refactor build
Browse files Browse the repository at this point in the history
  • Loading branch information
gilbarbara committed Nov 15, 2023
1 parent 2ddd706 commit 2869eae
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 75 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"@emotion/react": "^11.11.1",
"@emotion/styled": "^11.11.0",
"@gilbarbara/eslint-config": "^0.7.1",
"@gilbarbara/node-helpers": "^0.1.0",
"@gilbarbara/prettier-config": "^1.0.0",
"@gilbarbara/tsconfig": "^0.2.3",
"@gilbarbara/types": "^0.2.2",
Expand All @@ -65,7 +66,6 @@
"@types/react-dom": "^18.2.15",
"del-cli": "^5.1.0",
"disable-scroll": "^0.6.0",
"fix-tsup-cjs": "^1.2.0",
"husky": "^8.0.3",
"is-ci-cli": "^2.2.0",
"jest": "^29.7.0",
Expand All @@ -85,7 +85,7 @@
"typescript": "^5.2.2"
},
"scripts": {
"build": "npm run clean && tsup && fix-tsup-cjs",
"build": "npm run clean && tsup && ts-node scripts/fix-cjs.ts",
"watch": "tsup --watch",
"clean": "del dist/*",
"lint": "eslint src test",
Expand Down
84 changes: 13 additions & 71 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

57 changes: 57 additions & 0 deletions scripts/fix-cjs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { replaceContent, type ReplaceContentOptions } from '@gilbarbara/node-helpers';

export const fixCjsDts = async (options?: Partial<ReplaceContentOptions>) => {
return replaceContent({
pattern: '**/*.d.{ts,cts}',
...options,
name: 'fix-cjs-dts',

callback: content => {
const result = /(?<toReplace>\}\n\n(?<code>export .+))/u.exec(content);
const { code, toReplace } = result?.groups ?? {};

const exportEqual = 'export = ReactFloater;';

if (code) {
const statement = ` ${code}
}
${exportEqual}`;

if (!content.endsWith(exportEqual)) {
return content.replace(toReplace, '') + statement;
}
}

return false;
},
});
};

export const fixCjsExports = async (options?: Partial<ReplaceContentOptions>) => {
const statement = `
// fix-cjs-exports
if (module.exports.default) {
Object.assign(module.exports.default, module.exports);
module.exports = module.exports.default;
delete module.exports.default;
}
`;

return replaceContent({
pattern: '**/*.js',
...options,
name: 'fix-cjs-exports',

callback: content => {
if (content.includes('module.exports = __toCommonJS') && !content.endsWith(statement)) {
return content + statement;
}

return false;
},
});
};

fixCjsDts();
fixCjsExports();
2 changes: 1 addition & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ sonar.organization=gilbarbara-github
sonar.source=./src
sonar.javascript.lcov.reportPaths=./coverage/lcov.info
sonar.exclusions=**/demo/**/*.*,**/test/**/*.*
sonar.coverage.exclusions=**/test/**/*.*,**/jest.config.ts
sonar.coverage.exclusions=**/scripts/**/*.*,**/test/**/*.*,**/jest.config.ts
2 changes: 1 addition & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { useMount, useSingleton, useUnmount, useUpdateEffect } from './modules/h
import getStyles from './modules/styles';
import { Props, State, Statuses, Styles } from './types';

function ReactFloater(props: Props) {
function ReactFloater(props: Props): React.ReactElement {
const {
autoOpen,
callback,
Expand Down

0 comments on commit 2869eae

Please sign in to comment.