-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BREAKING CHANGE: first release
- Loading branch information
0 parents
commit a7985ba
Showing
16 changed files
with
8,828 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# http://editorconfig.org | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
indent_size = 2 | ||
indent_style = space | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
module.exports = { | ||
root: true, | ||
extends: ['airbnb', 'airbnb/base', 'prettier', 'prettier/react'], | ||
parser: '@babel/eslint-parser', | ||
env: { | ||
browser: true, | ||
jest: true, | ||
}, | ||
parserOptions: { | ||
ecmaVersion: 2018, | ||
sourceType: 'module', | ||
}, | ||
plugins: ['react-hooks', 'emotion'], | ||
rules: { | ||
'import/order': [ | ||
'error', | ||
{ | ||
groups: [ | ||
['builtin', 'external'], | ||
'internal', | ||
'parent', | ||
'sibling', | ||
'index', | ||
], | ||
alphabetize: { | ||
order: 'asc', | ||
caseInsensitive: false, | ||
}, | ||
'newlines-between': 'never', | ||
}, | ||
], | ||
|
||
'react/prop-types': 'off', | ||
'react/jsx-filename-extension': ['error', { extensions: ['.js'] }], | ||
'react/jsx-no-duplicate-props': ['warn', { ignoreCase: true }], | ||
}, | ||
settings: { | ||
'import/resolver': { | ||
node: { | ||
moduleDirectory: ['node_modules', 'src'], | ||
}, | ||
}, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
node_modules | ||
.eslintcache | ||
build | ||
coverage | ||
*.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# From .gitignore | ||
node_modules/ | ||
build/ | ||
|
||
# Specific to prettier | ||
package.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
These packages are unlicensed, and are only usable internally at Scaleway |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
# scaleway-lib | ||
|
||
scaleway-lib is a set of NPM packgages used at Scaleway. These libraries are available on our [private NPM registry](https://***REMOVED***). | ||
|
||
--- | ||
|
||
## Development | ||
|
||
### Locally | ||
|
||
```bash | ||
$ git clone git@***REMOVED***/scaleway-lib.git | ||
$ cd scaleway-lib | ||
$ yarn | ||
$ # ... do your changes ... | ||
$ yarn run lint | ||
$ yarn run test | ||
``` | ||
|
||
### Link against another project | ||
|
||
```bash | ||
$ cd packages/example_package | ||
$ yarn link | ||
$ cd - && yarn run build # rebuild the package | ||
$ cd ../fo-something | ||
$ yarn link @scaleway/example_package | ||
``` | ||
|
||
#### Linting | ||
|
||
```bash | ||
$ yarn run lint | ||
$ yarn run lint:fix | ||
``` | ||
|
||
#### Unit Test | ||
|
||
```bash | ||
$ yarn run test # Will run all tests | ||
$ yarn run test --updateSnapshot # Will update all snapshots | ||
$ yarn run test:watch # Will watch tests and only rerun the one who are modified | ||
$ yarn run test:coverage # Will generate a coverage report | ||
``` | ||
|
||
## Lerna | ||
|
||
This project is managed with [Lerna](https://lerna.js.org). Lerna is a tool to manage multiple NPM packages inside the same repository. | ||
|
||
Lerna also allows us to use [Yarn workspaces](https://classic.yarnpkg.com/en/docs/workspaces/) to manage our dependencies. This implies a few things: | ||
|
||
- devDependencies should be included in top package.json | ||
- There should be no `node_modules` or `yarn.lock` in sub-packages | ||
- There is a special syntax to manage sub-packages dependencies: | ||
|
||
```bash | ||
$ yarn add -W -D new_dependency # Add a new devDependency to root project | ||
$ yarn workspace @scaleway/package_name add new_dependency | ||
$ yarn workspace @scaleway/package_name remove old_dependency | ||
``` | ||
|
||
### Notes | ||
|
||
### On build targets | ||
|
||
We target by default Node@14 but you can add a browser output by adding a `browser` (you can find the spec [here](https://github.com/defunctzombie/package-browser-field-spec)) target to your `package.json`. | ||
|
||
```js | ||
"browser": { | ||
"build/index.js": "build/index.browser.js", | ||
"build/module.js": "build/module.browser.js" | ||
} | ||
``` | ||
|
||
The browserlist we are currently using is available in the [rollup.config.js](./rollup.config.js) | ||
|
||
Bear in mind that we do not currently support different entrypoint per target as we don't have the use case | ||
{: .alert .alert-warning} | ||
|
||
#### On build outputs | ||
|
||
We output both UMD and ESM files for each target. | ||
|
||
##### On commits | ||
|
||
We enforce the [conventionnal commits](https://www.conventionalcommits.org) convention in order to infer package bump versions and generate changelog. | ||
|
||
##### On versioning | ||
|
||
We follow the [semver](http://semver.org/) semantic. | ||
|
||
### Rules | ||
|
||
- Follow linter rules. | ||
- Ensure to have a tested code before merging. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"presets": ["@babel/preset-env"], | ||
"plugins": ["@babel/plugin-transform-runtime"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"packages": [ | ||
"packages/*" | ||
], | ||
"useWorkspaces": true, | ||
"npmClient": "yarn", | ||
"version": "independent", | ||
"command": { | ||
"publish": { | ||
"conventionalCommits": true | ||
}, | ||
"version": { | ||
"message": "chore(release): publish [skip-ci]" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
{ | ||
"name": "root", | ||
"private": true, | ||
"workspaces": [ | ||
"packages/*" | ||
], | ||
"devDependencies": { | ||
"@babel/core": "^7.12.3", | ||
"@babel/plugin-transform-runtime": "^7.12.1", | ||
"@babel/preset-env": "^7.12.1", | ||
"@commitlint/cli": "^11.0.0", | ||
"@commitlint/config-conventional": "^11.0.0", | ||
"@rollup/plugin-babel": "^5.2.1", | ||
"@rollup/plugin-commonjs": "^15.1.0", | ||
"@rollup/plugin-node-resolve": "^9.0.0", | ||
"builtin-modules": "^3.1.0", | ||
"cross-env": "^7.0.2", | ||
"husky": "^4.3.0", | ||
"jest": "^26.6.0", | ||
"lerna": "3.22.1", | ||
"lint-staged": "^10.4.2", | ||
"prettier": "^2.1.2", | ||
"read-pkg": "^5.2.0", | ||
"rollup": "^2.32.1", | ||
"rollup-plugin-analyzer": "^3.3.0" | ||
}, | ||
"scripts": { | ||
"build": "lerna exec --ignore @scaleway/eslint-* -- rollup -c ../../rollup.config.js", | ||
"build:profile": "cross-env PROFILE=true yarn run build", | ||
"test": "jest", | ||
"test:watch": "jest --watch", | ||
"test:coverage": "jest --coverage" | ||
}, | ||
"commitlint": { | ||
"extends": [ | ||
"@commitlint/config-conventional" | ||
] | ||
}, | ||
"husky": { | ||
"hooks": { | ||
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS", | ||
"pre-commit": "lint-staged", | ||
"pre-push": "lint-staged" | ||
} | ||
}, | ||
"lint-staged": { | ||
"*.js": [ | ||
"prettier --write", | ||
"eslint --fix" | ||
], | ||
"*.svg": [ | ||
"yarn optimize-svg" | ||
] | ||
}, | ||
"config": { | ||
"commitizen": { | ||
"path": "./node_modules/cz-conventional-changelog" | ||
} | ||
}, | ||
"jest": { | ||
"collectCoverageFrom": [ | ||
"src/**/*.{js,jsx}" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
**/__tests__/** | ||
src | ||
!.npmignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"name": "@scaleway/example_package", | ||
"version": "0.1.0", | ||
"description": "Sample package", | ||
"main": "build/index.js", | ||
"module": "build/module.js", | ||
"browser": { | ||
"build/index.js": "build/index.browser.js", | ||
"build/module.js": "build/module.browser.js" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/scaleway/scaleway-lib", | ||
"directory": "packages/example_package" | ||
}, | ||
"license": "UNLICENSED", | ||
"dependencies": { | ||
"lodash": "4.17.20" | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
packages/example_package/src/__tests__/__snapshots__/index.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`should calc 1`] = `4`; | ||
|
||
exports[`should pad 1`] = `" hello "`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { pad, calc } from ".."; | ||
|
||
it("should calc", () => { | ||
expect(calc(2, 2)).toMatchSnapshot(); | ||
}); | ||
|
||
it("should pad", () => { | ||
expect(pad("hello", 10)).toMatchSnapshot(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { pad as lodashPad } from "lodash"; | ||
|
||
export const calc = (a, b) => a + b; | ||
export const pad = (str, length) => lodashPad(str, length); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import babel from "@rollup/plugin-babel"; | ||
import readPkg from "read-pkg"; | ||
import resolve from "@rollup/plugin-node-resolve"; | ||
import commonjs from "@rollup/plugin-commonjs"; | ||
import builtins from "builtin-modules"; | ||
import analyze from "rollup-plugin-analyzer"; | ||
|
||
const PROFILE = !!process.env.PROFILE; | ||
|
||
const getConfig = (pkg, isBrowser = false) => { | ||
const targets = isBrowser | ||
? ` | ||
> 1%, | ||
last 2 versions, | ||
not IE > 0, | ||
not IE_Mob > 0 | ||
` | ||
: { node: "14" }; | ||
|
||
const external = (id) => | ||
[ | ||
...Object.keys(pkg.dependencies || {}), | ||
...Object.keys(pkg.peerDependencies || {}), | ||
...(isBrowser ? [] : builtins), | ||
].find((dep) => new RegExp(dep).test(id)); | ||
|
||
return { | ||
input: "./src/index.js", | ||
plugins: [ | ||
babel({ | ||
babelHelpers: "runtime", | ||
babelrc: false, | ||
exclude: "node_modules/**", | ||
presets: [["@babel/env", { modules: false, targets }]], | ||
plugins: ["@babel/plugin-transform-runtime"], | ||
}), | ||
resolve({ | ||
browser: isBrowser, | ||
preferBuiltins: true, | ||
}), | ||
commonjs({ | ||
include: "**/node_modules/**", | ||
}), | ||
PROFILE && analyze({ summaryOnly: true }), | ||
].filter(Boolean), | ||
external, | ||
output: [ | ||
{ | ||
format: "umd", | ||
name: pkg.name, | ||
file: isBrowser ? "build/index.browser.js" : "build/index.js", | ||
}, | ||
{ | ||
format: "es", | ||
file: isBrowser ? "build/module.browser.js" : "build/module.js", | ||
}, | ||
], | ||
}; | ||
}; | ||
|
||
export default async () => { | ||
const pkg = await readPkg(); | ||
|
||
const doesAlsoTargetBrowser = "browser" in pkg; | ||
|
||
return [getConfig(pkg), doesAlsoTargetBrowser && getConfig(pkg, true)].filter( | ||
Boolean | ||
); | ||
}; |
Oops, something went wrong.