Skip to content

Commit

Permalink
migrate from node-sass to dart-sass
Browse files Browse the repository at this point in the history
  • Loading branch information
bcamarneiro committed Jul 15, 2022
1 parent 637c3cc commit 61921b7
Show file tree
Hide file tree
Showing 8 changed files with 12,959 additions and 10,162 deletions.
5 changes: 5 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"trailingComma": "none",
"singleQuote": true,
"arrowParens": "avoid"
}
125 changes: 75 additions & 50 deletions gulpfile.babel.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,39 @@
import gulp from 'gulp';
import babel from 'gulp-babel';
import sass from 'gulp-sass';
import cleanCSS from 'gulp-clean-css';
import cleanDir from 'gulp-clean';
import rename from 'gulp-rename';
import shell from 'gulp-shell';
import gulp from "gulp";
import babel from "gulp-babel";
import gulpSass from "gulp-sass";
import dartSass from "sass";
import cleanCSS from "gulp-clean-css";
import cleanDir from "gulp-clean";
import rename from "gulp-rename";
import shell from "gulp-shell";

const LIB = 'lib';
const DIST = 'dist';
const TEST = 'test';
const PKG_PATH = './packages';
const NODE_MODULES = 'node_modules';
const sass = gulpSass(dartSass);
const LIB = "lib";
const DIST = "dist";
const TEST = "test";
const PKG_PATH = "./packages";
const NODE_MODULES = "node_modules";

const JS_PKGS = [
'react-bootstrap-table2',
'react-bootstrap-table2-editor',
'react-bootstrap-table2-filter',
'react-bootstrap-table2-overlay',
'react-bootstrap-table2-paginator',
'react-bootstrap-table2-toolkit'
].reduce((pkg, curr) => `${curr}|${pkg}`, '');
"react-bootstrap-table2",
"react-bootstrap-table2-editor",
"react-bootstrap-table2-filter",
"react-bootstrap-table2-overlay",
"react-bootstrap-table2-paginator",
"react-bootstrap-table2-toolkit",
].reduce((pkg, curr) => `${curr}|${pkg}`, "");

const JS_SKIPS = `+(${TEST}|${LIB}|${DIST}|${NODE_MODULES})`;

const STYLE_PKGS = [
'react-bootstrap-table2',
'react-bootstrap-table2-filter',
'react-bootstrap-table2-paginator',
'react-bootstrap-table2-toolkit',
].reduce((pkg, curr) => `${curr}|${pkg}`, '');
"react-bootstrap-table2",
"react-bootstrap-table2-filter",
"react-bootstrap-table2-paginator",
"react-bootstrap-table2-toolkit",
].reduce((pkg, curr) => `${curr}|${pkg}`, "");

const STYLE_SKIPS = `+(${NODE_MODULES})`;


function clean() {
return gulp
.src(`./packages/+(${JS_PKGS})/+(${LIB}|${DIST})`, { allowEmpty: true })
Expand All @@ -43,45 +44,69 @@ function scripts() {
return gulp
.src([
`./packages/+(${JS_PKGS})/**/*.js`,
`!packages/+(${JS_PKGS})/${JS_SKIPS}/**/*.js`
`!packages/+(${JS_PKGS})/${JS_SKIPS}/**/*.js`,
])
.pipe(babel())
.pipe(rename((path) => {
if (path.dirname.indexOf('src') > -1) {
path.dirname = path.dirname.replace('src', `${LIB}/src`);
} else {
path.dirname += `/${LIB}`;
}
}))
.pipe(
rename((path) => {
if (path.dirname.indexOf("src") > -1) {
path.dirname = path.dirname.replace("src", `${LIB}/src`);
} else {
path.dirname += `/${LIB}`;
}
})
)
.pipe(gulp.dest(PKG_PATH));
}

function styles() {
return gulp
.src([
`./packages/+(${STYLE_PKGS})/style/**/*.scss`,
`!packages/+(${STYLE_PKGS})/${STYLE_SKIPS}/**/*.scss`
`!packages/+(${STYLE_PKGS})/${STYLE_SKIPS}/**/*.scss`,
])
.pipe(sass().on('error', sass.logError))
.pipe(rename((path) => {
path.dirname = path.dirname.replace('style', DIST);
}))
.pipe(sass().on("error", sass.logError))
.pipe(
rename((path) => {
path.dirname = path.dirname.replace("style", DIST);
})
)
.pipe(gulp.dest(PKG_PATH))
.pipe(cleanCSS({ compatibility: 'ie8' }))
.pipe(rename((path) => {
path.extname = '.min.css';
}))
.pipe(cleanCSS({ compatibility: "ie8" }))
.pipe(
rename((path) => {
path.extname = ".min.css";
})
)
.pipe(gulp.dest(PKG_PATH));
}

function umd(done) {
gulp.parallel(
() => gulp.src('./webpack/next.umd.babel.js').pipe(shell(['webpack --config <%= file.path %>'])),
() => gulp.src('./webpack/editor.umd.babel.js').pipe(shell(['webpack --config <%= file.path %>'])),
() => gulp.src('./webpack/filter.umd.babel.js').pipe(shell(['webpack --config <%= file.path %>'])),
() => gulp.src('./webpack/overlay.umd.babel.js').pipe(shell(['webpack --config <%= file.path %>'])),
() => gulp.src('./webpack/paginator.umd.babel.js').pipe(shell(['webpack --config <%= file.path %>'])),
() => gulp.src('./webpack/toolkit.umd.babel.js').pipe(shell(['webpack --config <%= file.path %>']))
() =>
gulp
.src("./webpack/next.umd.babel.js")
.pipe(shell(["webpack --config <%= file.path %>"])),
() =>
gulp
.src("./webpack/editor.umd.babel.js")
.pipe(shell(["webpack --config <%= file.path %>"])),
() =>
gulp
.src("./webpack/filter.umd.babel.js")
.pipe(shell(["webpack --config <%= file.path %>"])),
() =>
gulp
.src("./webpack/overlay.umd.babel.js")
.pipe(shell(["webpack --config <%= file.path %>"])),
() =>
gulp
.src("./webpack/paginator.umd.babel.js")
.pipe(shell(["webpack --config <%= file.path %>"])),
() =>
gulp
.src("./webpack/toolkit.umd.babel.js")
.pipe(shell(["webpack --config <%= file.path %>"]))
)();
done();
}
Expand All @@ -90,5 +115,5 @@ const buildJS = gulp.parallel(umd, scripts);
const buildCSS = styles;
const build = gulp.series(clean, gulp.parallel(buildJS, buildCSS));

gulp.task('prod', build);
gulp.task('default', build);
gulp.task("prod", build);
gulp.task("default", build);
7 changes: 3 additions & 4 deletions lerna.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"lerna": "2.0.0",
"packages": [
"packages/*"
],
"version": "independent"
"packages": ["packages/*"],
"version": "independent",
"npmClient": "yarn"
}
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,19 @@
"gulp-clean": "0.4.0",
"gulp-clean-css": "3.9.2",
"gulp-rename": "^1.2.2",
"gulp-sass": "3.1.0",
"gulp-sass": "5.1.0",
"gulp-shell": "0.6.5",
"html-webpack-plugin": "2.30.1",
"jest": "20.0.4",
"jsdom": "11.2.0",
"jsdom-global": "3.0.2",
"lerna": "2.8.0",
"node-sass": "7.0.1",
"lerna": "4.0.0",
"sass": "^1.49.9",
"react-test-renderer": "16.0.0",
"sass-loader": "12.6.0",
"sass-loader": "^9.0.3",
"sinon": "3.2.1",
"style-loader": "0.17.0",
"webpack": "3.5.4",
"webpack": "4.41.2",
"webpack-dev-server": "2.7.1"
},
"dependencies": {
Expand Down
6 changes: 4 additions & 2 deletions packages/react-bootstrap-table2/src/store/sort.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function comparator(a, b) {
if (typeof b === 'string') {
result = b.localeCompare(a);
} else {
result = a > b ? -1 : ((a < b) ? 1 : 0);
result = a > b ? -1 : a < b ? 1 : 0;
}
return result;
}
Expand Down Expand Up @@ -47,6 +47,8 @@ export const nextOrder = (
{ sortOrder, sortColumn },
defaultOrder = Const.SORT_DESC
) => {
if (!sortColumn || currentSortColumn.dataField !== sortColumn.dataField) return defaultOrder;
if (!sortColumn || currentSortColumn.dataField !== sortColumn.dataField) {
return defaultOrder;
}
return sortOrder === Const.SORT_DESC ? Const.SORT_ASC : Const.SORT_DESC;
};
6 changes: 4 additions & 2 deletions packages/react-bootstrap-table2/test/store/sort.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('Sort Function', () => {
const sortFunc = sinon.stub().returns(1);
sortOrder = Const.SORT_DESC;
sort(data, sortOrder, { ...sortColumn, sortFunc });
expect(sortFunc.callCount).toBe(6);
expect(sortFunc.callCount).toBe(3);
});
});

Expand Down Expand Up @@ -77,7 +77,9 @@ describe('Sort Function', () => {
},
sortOrder: Const.SORT_DESC
};
expect(nextOrder(currentSortColumn, nextSort, Const.SORT_ASC)).toBe(Const.SORT_ASC);
expect(nextOrder(currentSortColumn, nextSort, Const.SORT_ASC)).toBe(
Const.SORT_ASC
);
});

it('should return correcly order when current sortField is eq next sort field', () => {
Expand Down
70 changes: 37 additions & 33 deletions webpack/webpack.umd.babel.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,49 @@
import webpack from 'webpack';
import webpack from "webpack";

module.exports = {
devtool: 'source-map',
externals: [{
'react': {
root: 'React',
commonjs2: 'react',
commonjs: 'react',
amd: 'react'
}
}, {
'react-dom': {
root: 'ReactDOM',
commonjs2: 'react-dom',
commonjs: 'react-dom',
amd: 'react-dom'
}
}],
devtool: "source-map",
mode: "production",
externals: [
{
react: {
root: "React",
commonjs2: "react",
commonjs: "react",
amd: "react",
},
},
{
"react-dom": {
root: "ReactDOM",
commonjs2: "react-dom",
commonjs: "react-dom",
amd: "react-dom",
},
},
],
module: {
rules: [{
enforce: 'pre',
test: /\.js?$/,
exclude: /node_modules/,
loader: 'eslint-loader'
}, {
test: /\.js?$/,
use: ['babel-loader'],
exclude: /node_modules/
}]
rules: [
{
enforce: "pre",
test: /\.js?$/,
exclude: /node_modules/,
loader: "eslint-loader",
},
{
test: /\.js?$/,
use: ["babel-loader"],
exclude: /node_modules/,
},
],
},
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production')
}),
new webpack.SourceMapDevToolPlugin(),
new webpack.optimize.DedupePlugin(),
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.optimize.AggressiveMergingPlugin(),
new webpack.optimize.UglifyJsPlugin({
include: /\.min\.js$/,
compress: { warnings: false }
})
]
compress: { warnings: false },
}),
],
};
Loading

0 comments on commit 61921b7

Please sign in to comment.