Skip to content
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

Fix importing error for reexported adapters #1634

Merged
merged 1 commit into from
Apr 11, 2020
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
24 changes: 12 additions & 12 deletions lib/.size-snapshot.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
{
"build/dist/material-ui-pickers.esm.js": {
"bundled": 190777,
"minified": 103329,
"gzipped": 26701,
"bundled": 191726,
"minified": 103839,
"gzipped": 26870,
"treeshaked": {
"rollup": {
"code": 85805,
"import_statements": 2112
"code": 86187,
"import_statements": 2162
},
"webpack": {
"code": 95022
"code": 95489
}
}
},
"build/dist/material-ui-pickers.umd.js": {
"bundled": 300842,
"minified": 118907,
"gzipped": 33715
"bundled": 301808,
"minified": 119265,
"gzipped": 33834
},
"build/dist/material-ui-pickers.umd.min.js": {
"bundled": 259632,
"minified": 109852,
"gzipped": 30972
"bundled": 260598,
"minified": 110210,
"gzipped": 31113
}
}
58 changes: 0 additions & 58 deletions lib/copy.js

This file was deleted.

4 changes: 2 additions & 2 deletions lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@
"test:moment": "UTILS=moment yarn test",
"start": "rollup --config rollup.config.dev.js --watch & npx tsc --watch",
"prebuild": "rimraf build",
"build:copy": "node copy.js",
"build:prepare-files": "node prepare-build-files.js",
"build:bundle": "rollup --config",
"build:typescript": "tsc --project tsconfig.json",
"build": "yarn build:typescript && yarn build:bundle && yarn build:copy",
"build": "yarn build:typescript && yarn build:bundle && yarn build:prepare-files",
"build:analyze": "yarn build",
"release": "yarn test && yarn version && yarn build && yarn publish --non-interactive --tag next build"
},
Expand Down
70 changes: 70 additions & 0 deletions lib/prepare-build-files.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
const path = require('path');
const fse = require('fs-extra');

function copyReadme() {
return fse
.copyFile(
path.resolve(__dirname, '..', 'README.md'),
path.resolve(__dirname, 'build', 'README.md')
)
.then(() => console.log('> Copied README.md'));
}

function createAdapterPackageFile(name) {
const packageJson = {
name: `@material-ui/pickers-adapter-${name}`,
Copy link
Member Author

@dmtrKovalenko dmtrKovalenko Apr 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@oliviertassinari What do you think will be the best name for adapter package.json?
BTW @material-ui/pickers/adapter/${name} is not a valid name for package.json

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we even need to provide a name? For instance: https://unpkg.com/browse/@material-ui/core@4.9.9/Badge/package.json.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We had mui/material-ui#15715, but it seemed fine.

module: 'index.js',
main: 'index.cjs.js',
typings: `../${name}.d.ts`,
};

return fse.writeFile(
path.resolve(__dirname, 'build', 'adapter', name, 'package.json'),
JSON.stringify(packageJson, null, 2)
);
}

function createAdaptersPackages() {
return Promise.all(
['luxon', 'date-fns', 'dayjs', 'moment'].map(createAdapterPackageFile)
).then(() => console.log('> Created package.json files for adapters'));
}

function createRootPackageFile() {
return fse
.readFile(path.resolve(__dirname, 'package.json'), 'utf8')
.then(data => JSON.parse(data))
.then(packageData => {
// cleanup produced package
const {
devDependencies,
jest,
husky,
main,
module,
'lint-staged': ls,
...other
} = packageData;

const newPackage = {
...other,
private: false,
main: './dist/material-ui-pickers.js',
module: './index.js',
typings: './src/index.d.ts',
};

const buildPath = path.resolve(__dirname, 'build', 'package.json');
const data = JSON.stringify(newPackage, null, 2);

return fse
.writeFile(buildPath, data)
.then(() => console.log(`> Created package.json in ${buildPath}`));
});
}

createRootPackageFile()
.then(copyReadme)
.then(createAdaptersPackages)
.then(() => console.log('\nFinished build files preparation'))
.catch(console.error);
19 changes: 9 additions & 10 deletions lib/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ const globals = {
'@material-ui/core/Grid': 'material-ui.Grid',
'@material-ui/core/IconButton': 'material-ui.IconButton',
'@material-ui/core/InputAdornment': 'material-ui.InputAdornment',
'@material-ui/core/utils': 'material-ui.utils',
'@material-ui/core/Paper': 'material-ui.Paper',
'@material-ui/core/Popover': 'material-ui.Popover',
'@material-ui/core/styles': 'material-ui',
Expand Down Expand Up @@ -124,10 +123,10 @@ export default [

{
input: {
'date-fns': './adapter/date-fns',
luxon: './adapter/luxon',
moment: './adapter/moment',
dayjs: './adapter/dayjs',
'date-fns/index': './adapter/date-fns',
'luxon/index': './adapter/luxon',
'moment/index': './adapter/moment',
'dayjs/index': './adapter/dayjs',
},
external,
onwarn,
Expand All @@ -136,15 +135,15 @@ export default [
format: 'esm',
sourcemap: true,
},
plugins: getCommonPlugins({ esm: true }),
plugins: getCommonPlugins({ esm: false }),
},

{
input: {
'date-fns.cjs': './adapter/date-fns',
'luxon.cjs': './adapter/luxon',
'moment.cjs': './adapter/moment',
'dayjs.cjs': './adapter/dayjs',
'date-fns/index.cjs': './adapter/date-fns',
'luxon/index.cjs': './adapter/luxon',
'moment/index.cjs': './adapter/moment',
'dayjs/index.cjs': './adapter/dayjs',
},
external,
onwarn,
Expand Down