Skip to content

Commit

Permalink
Merge changes of react-helmet 6
Browse files Browse the repository at this point in the history
  • Loading branch information
kouhin committed May 21, 2019
1 parent 3e4b40f commit 21bcd0e
Show file tree
Hide file tree
Showing 9 changed files with 348 additions and 1,367 deletions.
63 changes: 0 additions & 63 deletions .babelrc

This file was deleted.

19 changes: 19 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module.exports = {
presets: [
[
"@babel/preset-env",
{
targets: {
browsers: ["last 1 versions", "ie >= 10"]
},
modules: false,
loose: true
}
],
"@babel/preset-react"
],
plugins: [
"@babel/plugin-proposal-class-properties",
"@babel/plugin-proposal-object-rest-spread"
]
};
52 changes: 30 additions & 22 deletions karma.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,18 @@ module.exports = function(config) {

client: {
mocha: {
bail: false,
bail: true,
reporter: "html"
}
},

// frameworks to use
frameworks: ["chai-sinon", "mocha"],

files: ["./test/test.js"],
files: ["./test/*.js"],

preprocessors: {
// add webpack as preprocessor
"./test/test.js": ["webpack", "sourcemap"]
"./test/*.js": ["rollup", "sourcemap"]
},

coverageReporter: {
Expand All @@ -40,24 +39,32 @@ module.exports = function(config) {
]
},

webpack: {
mode: "development",
devtool: "inline-source-map",
module: {
rules: [
{
test: /\.js$/,
// exclude this dirs from coverage
exclude: [/node_modules/],
loader: "babel-loader"
}
]
rollupPreprocessor: {
output: {
format: "iife",
name: "helmet",
sourcemap: "inline"
},
watch: true
},

webpackServer: {
noInfo: true
plugins: [
require("rollup-plugin-replace")({
"process.env.NODE_ENV": "'development'"
}),
require("rollup-plugin-babel")({
exclude: "node_modules/**",
plugins: [
[
"istanbul",
{
exclude: ["**/node_modules/**", "**/test/**"]
}
]
]
}),
require("rollup-plugin-node-resolve")({
browser: true
}),
require("rollup-plugin-commonjs")()
]
},

// test results reporter to use
Expand All @@ -80,9 +87,10 @@ module.exports = function(config) {
// Start these browsers, currently available:
// - Chrome
// - ChromeCanary
// - Firefox (has to be installed with `npm install karma-firefox-launcher`)
// - Firefox
// - Opera (has to be installed with `npm install karma-opera-launcher`)
// - Safari (only Mac; has to be installed with `npm install karma-safari-launcher`)
// - PhantomJS
// - IE (only Windows; has to be installed with `npm install karma-ie-launcher`)
browsers: process.env.TRAVIS ? ["ChromeTravis"] : ["Chrome"],

Expand Down
30 changes: 14 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"name": "react-safety-helmet",
"description": "A fork of react-helmet that support for renderToNodeStream and thread safe, provides both react hooks and declarative api",
"version": "6.3.0",
"main": "./lib/index.js",
"module": "es/index.js",
"main": "./lib/Helmet.js",
"module": "es/Helmet.js",
"sideEffect": false,
"author": "Bin Hou <[email protected]> (https://github.com/kouhin)",
"contributors": [
Expand Down Expand Up @@ -38,27 +38,23 @@
"react": ">=16.8.0"
},
"dependencies": {
"core-js": "2",
"exenv": "^1.2.2",
"prop-types": "^15.7.2",
"react-fast-compare": "^2.0.4"
},
"devDependencies": {
"@babel/cli": "^7.4.4",
"@babel/core": "^7.4.4",
"@babel/plugin-external-helpers": "^7.2.0",
"@babel/plugin-proposal-class-properties": "^7.4.4",
"@babel/plugin-proposal-object-rest-spread": "^7.4.4",
"@babel/plugin-transform-strict-mode": "^7.2.0",
"@babel/preset-env": "^7.4.4",
"@babel/preset-react": "^7.0.0",
"babel-eslint": "^10.0.1",
"babel-loader": "^8.0.6",
"babel-plugin-add-module-exports": "^1.0.2",
"babel-plugin-istanbul": "^5.1.4",
"babel-plugin-transform-remove-strict-mode": "^0.0.2",
"chai": "^4.2.0",
"codecov": "^3.5.0",
"conventional-changelog-cli": "^2.0.21",
"cross-env": "^5.2.0",
"cz-conventional-changelog": "^2.1.0",
"eslint": "^5.16.0",
"eslint-config-nfl": "^12.0.0",
Expand All @@ -77,31 +73,33 @@
"karma-coverage": "^1.1.2",
"karma-html-reporter": "^0.2.7",
"karma-mocha": "^1.3.0",
"karma-rollup-preprocessor": "^7.0.0",
"karma-sourcemap-loader": "^0.3.7",
"karma-spec-reporter": "^0.0.32",
"karma-tap-reporter": "^0.0.6",
"karma-webpack": "^3.0.5",
"mocha": "^6.1.4",
"prettier": "^1.17.1",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"rimraf": "^2.6.3",
"rollup": "^1.12.1",
"rollup-plugin-babel": "^4.3.2",
"rollup-plugin-commonjs": "^10.0.0",
"rollup-plugin-node-resolve": "^5.0.0",
"rollup-plugin-replace": "^2.2.0",
"sinon": "^7.3.2",
"sinon-chai": "^3.3.0",
"webpack": "^4.31.0"
"sinon-chai": "^3.3.0"
},
"scripts": {
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s",
"clean": "rimraf lib coverage es",
"lint": "eslint --ignore-path .gitignore --fix -- .",
"test": "cross-env BABEL_ENV=test karma start karma.config.js",
"test": "karma start karma.config.js",
"posttest": "istanbul report lcov text",
"pretest": "npm run clean && npm run lint",
"commit": "git-cz",
"compile": "npm run compile:commonjs && npm run compile:es",
"compile:commonjs": "cross-env BABEL_ENV=commonjs babel src --out-dir lib",
"compile:es": "cross-env BABEL_ENV=es babel src --out-dir es --ignore test.js",
"prepublish": "npm run compile"
"build": "rollup -c",
"prepublish": "npm run build"
},
"config": {
"commitizen": {
Expand Down
37 changes: 37 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import babel from "rollup-plugin-babel";

import pkg from "./package.json";

const baseConfig = {
input: "src/index.js",
plugins: [
babel({
exclude: "node_modules/**"
})
],
external: [
...Object.keys(pkg.dependencies),
...Object.keys(pkg.peerDependencies)
]
};

export default [
Object.assign(
{
output: {
file: "lib/Helmet.js",
format: "cjs"
}
},
baseConfig
),
Object.assign(
{
output: {
file: "es/Helmet.js",
format: "esm"
}
},
baseConfig
)
];
20 changes: 11 additions & 9 deletions src/Helmet.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
import React, {
createContext,
useLayoutEffect,
useEffect,
useCallback,
useMemo,
useContext,
useRef
} from "react";
import React from "react";
import ExecutionEnvironment from "exenv";
import PropTypes from "prop-types";
import deepEqual from "react-fast-compare";
Expand All @@ -21,6 +13,16 @@ import {
import {TAG_NAMES, VALID_TAG_NAMES} from "./HelmetConstants";
import rootReducer, {addProps, removeProps} from "./modules";

const {
createContext,
useLayoutEffect,
useEffect,
useCallback,
useMemo,
useContext,
useRef
} = React;

const HelmetContext = createContext();
HelmetContext.displayName = "HelmetContext";

Expand Down
6 changes: 5 additions & 1 deletion src/HelmetUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ const getTitleFromPropsList = propsList => {

if (innermostTemplate && innermostTitle) {
// use function arg to avoid need to escape $ characters
return innermostTemplate.replace(/%s/g, () => innermostTitle);
return innermostTemplate.replace(/%s/g, () =>
Array.isArray(innermostTitle)
? innermostTitle.join("")
: innermostTitle
);
}

const innermostDefaultTitle = getInnermostProperty(
Expand Down
2 changes: 0 additions & 2 deletions test/test.js

This file was deleted.

Loading

0 comments on commit 21bcd0e

Please sign in to comment.