Skip to content

Commit

Permalink
✨ Add metadata on the generated sources (#526) (#540)
Browse files Browse the repository at this point in the history
  • Loading branch information
dubzzz authored Jan 26, 2020
1 parent c2de4fc commit f4abc62
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .codesandbox/ci.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@


{
"buildCommand": "build",
"buildCommand": "build:prod",
"sandboxes": ["vanilla", "/example"]
}

Expand Down
12 changes: 2 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,7 @@ jobs:
- stage: test
env: STEP=EXAMPLES_ROLLUP_LEGACY_TYPES
script:
- yarn prebuild
- yarn build:publish-types
- yarn build:publish-cjs
- yarn build:publish-esm
- yarn webbuild
- yarn build:prod
- yarn link
- cd example ;
yarn --ignore-engines ;
Expand Down Expand Up @@ -84,11 +80,7 @@ jobs:
- stage: deploy
if: tag =~ ^v\d+\.
script:
- yarn prebuild
- yarn build:publish-types
- yarn build:publish-cjs
- yarn build:publish-esm
- yarn webbuild
- yarn build:prod
deploy:
provider: npm
email: [email protected]
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
"build:watch": "tsc -w",
"build:publish-types": "tsc -p tsconfig.publish.types.json && node ./buildTypes.js",
"build:publish-cjs": "tsc -p tsconfig.publish.json",
"build:publish-esm": "tsc -p tsconfig.publish.json --module es2015 --moduleResolution node --outDir lib/esm && node postbuild/main.js",
"build:publish-esm": "tsc -p tsconfig.publish.json --module es2015 --moduleResolution node --outDir lib/esm",
"webbuild": "browserify lib/fast-check.js --s fastcheck | uglifyjs -cm > lib/bundle.js",
"build:prod": "yarn prebuild && yarn build:publish-cjs && yarn build:publish-esm && yarn build:publish-types && yarn webbuild && node postbuild/main.js",
"watch": "tsc -w",
"test": "jest --config jest.unit.config.js --coverage",
"test:watch": "jest --config jest.unit.config.js --watch",
Expand Down
39 changes: 39 additions & 0 deletions postbuild/main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
// eslint-disable-next-line
const fs = require('fs');
// eslint-disable-next-line
const path = require('path');
// eslint-disable-next-line
const replace = require('replace-in-file');

// Append *.js file extension on all local imports

const options = {
files: 'lib/**/*.js',
from: [/from '\.(.*)(?<!\.js)'/g, /from "\.(.*)(?<!\.js)"/g],
Expand All @@ -14,3 +20,36 @@ for (const { file, hasChanged } of results) {
console.info(`Extensions added to: ${file}`);
}
}

// Fill metas related to the package

// eslint-disable-next-line
fs.readFile(path.join(__dirname, '../package.json'), (err, data) => {
if (err) {
// eslint-disable-next-line
console.error(err.message);
return;
}

const packageVersion = JSON.parse(data.toString()).version;

const commonJsReplacement = replace.sync({
files: 'lib/fast-check-default.js',
from: [/__PACKAGE_TYPE__/g, /__PACKAGE_VERSION__/g],
to: ['commonjs', packageVersion]
});
if (commonJsReplacement.length === 1 && commonJsReplacement[0].hasChanged) {
// eslint-disable-next-line
console.info(`Package details added onto commonjs version`);
}

const moduleReplacement = replace.sync({
files: 'lib/esm/fast-check-default.js',
from: [/__PACKAGE_TYPE__/g, /__PACKAGE_VERSION__/g],
to: ['module', packageVersion]
});
if (moduleReplacement.length === 1 && moduleReplacement[0].hasChanged) {
// eslint-disable-next-line
console.info(`Package details added onto module version`);
}
});
7 changes: 7 additions & 0 deletions src/fast-check-default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ import { Stream, stream } from './stream/Stream';
import { stringify } from './utils/stringify';
import { scheduler, Scheduler, SchedulerSequenceItem } from './check/arbitrary/AsyncSchedulerArbitrary';

// Explicit cast into string to avoid to have __type: "__PACKAGE_TYPE__"
const __type = '__PACKAGE_TYPE__' as string;
const __version = '__PACKAGE_VERSION__' as string;

// boolean
// floating point types
// integer types
Expand All @@ -97,6 +101,9 @@ import { scheduler, Scheduler, SchedulerSequenceItem } from './check/arbitrary/A
// combination of others
// complex combinations
export {
// meta
__type,
__version,
// assess the property
sample,
statistics,
Expand Down

0 comments on commit f4abc62

Please sign in to comment.