Skip to content

Commit

Permalink
Fix importing error for reexported adapters
Browse files Browse the repository at this point in the history
  • Loading branch information
dmtrKovalenko committed Apr 10, 2020
1 parent 502118d commit 03e6992
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 82 deletions.
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}`,
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

0 comments on commit 03e6992

Please sign in to comment.