Skip to content

Commit

Permalink
Merge pull request #5583 from alibaba/release/3.0
Browse files Browse the repository at this point in the history
* chore: version

* feat: redirect imports (#5590)

* feat: redirect imports

* test: data loader size

* chore: change log

* chore: change log

* feat: support partial match of redirect import (#5591)

* feat: support partial match of redirect import

* fix: optimize code

* feat: server external (#5572)

* feat: server only external

* refactor: alias to resolve

* fix: resolve path

* fix: type

* fix: lint

* fix: pass a timeout value for long-running test (#5604)

* fix: pass a timeout value for long-running test

* fix: configure testTimeout

* fix: re-order compilation of redirect import (#5606)

* fix: get route config by route id in plugin pha (#5609)

* fix: route match of plugin pha

* Update manifestHelpers.ts

* chore: changelog

* feat: support multiple runtime entry of development (#5596)

* feat: support multiple runtime entry of development

* feat: optimize code

* fix: bump versions of dependencies (#5598)

* fix: bump versions of dependencies

* fix: update lock

* chore: changelog

* fix: server output files (#5608)

* fix: not generate source map file when set sourceMap to true

* feat: remove reduplicative server files

* fix: comment

* fix: test error

* feat: path is incorrect in windows

* chore: add log

* fix: test fail in windows

* fix: fail to run in windows

* Feat/lock version (#5616)

* refactor: lock file by ice bundles

* fix: using lower case for swc plugin export

* chore: update repo and changelog (#5618)

* chore: add changelog and docs update

* docs: update docs repo

* Update CHANGELOG.md

* fix: add temp file to cache dir (#5623)

* fix: support custom config file (#5622)

* fix: merge context for component(#5630)

Co-authored-by: 水澜 <[email protected]>
Co-authored-by: luhc228 <[email protected]>
Co-authored-by: ZeroLing <[email protected]>
  • Loading branch information
4 people authored Nov 29, 2022
2 parents 564638e + 60cad35 commit 3d8bcff
Show file tree
Hide file tree
Showing 72 changed files with 1,156 additions and 568 deletions.
2 changes: 2 additions & 0 deletions examples/basic-project/src/pages/index.module.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@import "var.scss";

.data {
margin-top: 10px;
}
1 change: 1 addition & 0 deletions examples/basic-project/src/pages/var.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$color-1 : #fff;
11 changes: 11 additions & 0 deletions packages/bundles/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Changelog

## 0.1.1

- [fix] Bump version of `@swc/core`(1.3.3 -> 1.3.19), https://github.com/swc-project/swc/issues/6371
- [fix] Bump version of `caniuse-lite`(^1.0.30001332 -> ^1.0.30001431), postcss requires version upper than 1.0.30001400
- [fix] Bump version of `webpack`(5.74.0 -> 5.75.0), minor version update
- [add] Add `@ice/swc-plugin-remove-export`(0.1.2)
- [add] Add `@ice/swc-plugin-keep-export`(0.1.3)
- [add] Add `@ice/swc-plugin-keep-platform`(0.1.2)
- [add] Add `core-js`(3.26.0)
12 changes: 8 additions & 4 deletions packages/bundles/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ice/bundles",
"version": "0.1.0",
"version": "0.1.1",
"license": "MIT",
"author": "ICE",
"description": "Basic dependencies for ice.",
Expand All @@ -15,10 +15,14 @@
"main": "./esm/index.js",
"type": "module",
"dependencies": {
"@swc/core": "1.3.19",
"@ice/swc-plugin-remove-export": "0.1.2",
"@ice/swc-plugin-keep-export": "0.1.3",
"@ice/swc-plugin-keep-platform": "0.1.2",
"ansi-html-community": "^0.0.8",
"html-entities": "^2.3.2",
"@swc/core": "1.3.3",
"caniuse-lite": "^1.0.30001332",
"core-js": "3.26.0",
"caniuse-lite": "^1.0.30001431",
"chokidar": "3.5.3",
"events": "3.3.0",
"jest-worker": "27.5.1",
Expand Down Expand Up @@ -61,7 +65,7 @@
"terser-webpack-plugin": "5.3.5",
"typescript": "^4.6.4",
"trusted-cert": "1.1.3",
"webpack": "5.74.0",
"webpack": "5.75.0",
"webpack-bundle-analyzer": "4.5.0",
"webpack-dev-server": "4.10.0",
"unplugin": "0.9.5",
Expand Down
22 changes: 21 additions & 1 deletion packages/bundles/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,32 @@
// reexport for dependencies
import { createRequire } from 'module';
import { dirname } from 'path';
import postcss from 'postcss';
import less from 'less';
import sass from 'sass';
import swc from '@swc/core';

const require = createRequire(import.meta.url);
const swcPluginRemoveExport = require.resolve('@ice/swc-plugin-remove-export');
const swcPluginKeepExport = require.resolve('@ice/swc-plugin-keep-export');
const swcPluginKeepPlatform = require.resolve('@ice/swc-plugin-keep-platform');
const coreJsPath = dirname(require.resolve('core-js/package.json'));

export {
postcss,
less,
sass,

swc,
swcPluginRemoveExport,
swcPluginKeepExport,
swcPluginKeepPlatform,

coreJsPath,
};

export type { ProcessOptions } from 'postcss';
export type {
Options as SwcConfig,
Config as SwcCompilationConfig,
ReactConfig,
} from '@swc/core';
9 changes: 8 additions & 1 deletion packages/ice/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## v3.0.1

- [fix] file resolve when use css module in server compiling
- [fix] lock version of `@ice/bundles`, `@ice/webpack-config` and `@ice/route-manifest`
- [feat] support external config for server
- [feat] redirect imports for data loader

## v3.0.0

- [feat] provider basic service for web framework `ice`
- [feat] provider basic service for web framework `ice`
14 changes: 7 additions & 7 deletions packages/ice/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ice/app",
"version": "3.0.0",
"version": "3.0.1",
"description": "provide scripts and configuration used by web framework ice",
"type": "module",
"main": "./esm/index.js",
Expand Down Expand Up @@ -29,18 +29,18 @@
},
"author": "ice-admin",
"license": "MIT",
"repository": "ice-lab/ice-next",
"bugs": "https://github.com/ice-lab/ice-next/issues",
"homepage": "https://next.ice.work",
"repository": "alibaba/ice",
"bugs": "https://github.com/alibaba/ice/issues",
"homepage": "https://v3.ice.work",
"dependencies": {
"@babel/generator": "7.18.10",
"@babel/parser": "7.18.10",
"@babel/traverse": "7.18.10",
"@babel/types": "7.18.10",
"@ice/bundles": "^0.1.0",
"@ice/route-manifest": "^1.0.0",
"@ice/bundles": "0.1.1",
"@ice/route-manifest": "1.0.0",
"@ice/runtime": "^1.0.0",
"@ice/webpack-config": "^1.0.0",
"@ice/webpack-config": "1.0.1",
"@swc/helpers": "0.4.12",
"@types/express": "^4.17.14",
"address": "^1.1.2",
Expand Down
18 changes: 10 additions & 8 deletions packages/ice/src/createService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,17 @@ interface CreateServiceOptions {

async function createService({ rootDir, command, commandArgs }: CreateServiceOptions) {
const buildSpinner = createSpinner('loading config...');
const templateDir = path.join(__dirname, '../templates/core/');
const configFile = 'ice.config.(mts|mjs|ts|js|cjs|json)';
const templateDir = path.join(__dirname, '../templates/');
const coreTemplate = path.join(templateDir, 'core/');
const configFile = commandArgs.config || 'ice.config.(mts|mjs|ts|js|cjs|json)';
const dataCache = new Map<string, string>();
const generator = new Generator({
// Directory of templates includes `core` and `exports`.
templateDir,
rootDir,
targetDir: RUNTIME_TMP_DIR,
// add default template of ice
templates: [templateDir],
templates: [coreTemplate],
});

const { addWatchEvent, removeWatchEvent } = createWatch({
Expand Down Expand Up @@ -159,20 +162,20 @@ async function createService({ rootDir, command, commandArgs }: CreateServiceOpt
const platformTaskConfig = taskConfigs[0];

const iceRuntimePath = '@ice/runtime';
const enableRoutes = platform === WEB;
// add render data
generator.setRenderData({
...routesInfo,
platform,
iceRuntimePath,
enableRoutes,
hasExportAppData,
runtimeModules,
coreEnvKeys,
basename: platformTaskConfig.config.basename || '/',
memoryRouter: platformTaskConfig.config.memoryRouter,
hydrate: !csr,
importCoreJs: polyfill === 'entry',
// Enable react-router for web as default.
enableRoutes: true,
});
dataCache.set('routes', JSON.stringify(routesInfo));
dataCache.set('hasExportAppData', hasExportAppData ? 'true' : '');
Expand All @@ -184,7 +187,7 @@ async function createService({ rootDir, command, commandArgs }: CreateServiceOpt
}, generator.addRenderFile, {
rootDir,
runtimeDir: RUNTIME_TMP_DIR,
templateDir: path.join(templateDir, '../exports'),
templateDir: path.join(templateDir, 'exports'),
dataLoader: userConfig.dataLoader,
});

Expand All @@ -207,10 +210,9 @@ async function createService({ rootDir, command, commandArgs }: CreateServiceOpt
...getWatchEvents({
generator,
targetDir: RUNTIME_TMP_DIR,
templateDir,
templateDir: coreTemplate,
cache: dataCache,
ctx,
serverCompiler,
}),
);

Expand Down
9 changes: 7 additions & 2 deletions packages/ice/src/esbuild/cssModules.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as path from 'path';
import url from 'url';
import fse from 'fs-extra';
import temp from 'temp';
import cssModules from '@ice/bundles/compiled/postcss-modules/index.js';
Expand Down Expand Up @@ -90,11 +91,15 @@ async function parseStyle(filePath: string) {
}

if (ext === '.scss') {
return (await sass.compileStringAsync(content)).css;
return (await sass.compileStringAsync(content, {
url: url.pathToFileURL(filePath),
})).css;
}

if (ext === '.less') {
return (await less.render(content)).css;
return (await less.render(content, {
filename: filePath,
})).css;
}

throw new Error(`Can't parse the style '${ext}'.`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,23 @@ interface PluginOptions {
alias: Record<string, string | false>;
externalDependencies: boolean;
format: BuildOptions['format'];
externals?: string[];
}

const aliasPlugin = (options: PluginOptions): Plugin => {
const { alias, externalDependencies, format } = options;
const resolvePlugin = (options: PluginOptions): Plugin => {
const { alias, externalDependencies, format, externals } = options;
return {
name: 'esbuild-alias',
name: 'esbuild-resolve',
setup(build: PluginBuild) {
build.onResolve({ filter: /.*/ }, (args) => {
const id = args.path;

// ice do not support alias with config onlyModule
const resolved = resolveId(id, alias);

if (resolved && resolved !== id) {
let resolvedPath = resolved;

// glob specified file module aliased with absolute path
if (!path.extname(resolved) && path.isAbsolute(resolved)) {
const basename = path.basename(resolved);
Expand All @@ -28,26 +33,53 @@ const aliasPlugin = (options: PluginOptions): Plugin => {
cwd: path.dirname(resolved),
absolute: true,
})[0];

if (absoluteId) {
return {
path: absoluteId,
};
resolvedPath = absoluteId;
}
}
return { path: resolved };

const external = shouldExternal(resolvedPath, externals);

// absolute path can not be resolved by other plugins, so we need to check external here.
if (external) {
return {
path: resolvedPath,
external: true,
};
}

return { path: resolvedPath };
}
});
build.onResolve({ filter: /.*/ }, (args) => {
const id = args.path;

// external ids which is third-party dependencies
if (id[0] !== '.' && !path.isAbsolute(id) && externalDependencies && isExternalBuiltinDep(id, format)) {
return {
external: true,
};
}

const external = shouldExternal(id, externals);

if (external) {
return {
path: id,
external: true,
};
}
});
},
};
};

export default aliasPlugin;
function shouldExternal(id: string, externals?: string[]) {
if (!externals) {
return;
}

return externals.find(regexStr => {
return new RegExp(regexStr).test(id);
});
}

export default resolvePlugin;
3 changes: 1 addition & 2 deletions packages/ice/src/getWatchEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as path from 'path';
import consola from 'consola';
import type { Context } from 'build-scripts';
import type { Config } from '@ice/webpack-config/esm/types';
import type { ServerCompiler, WatchEvent } from './types/plugin.js';
import type { WatchEvent } from './types/plugin.js';
import { generateRoutesInfo } from './routes.js';
import type Generator from './service/runtimeGenerator';
import getGlobalStyleGlobPattern from './utils/getGlobalStyleGlobPattern.js';
Expand All @@ -15,7 +15,6 @@ interface Options {
generator: Generator;
cache: Map<string, string>;
ctx: Context<Config>;
serverCompiler: ServerCompiler;
}

const getWatchEvents = (options: Options): WatchEvent[] => {
Expand Down
4 changes: 2 additions & 2 deletions packages/ice/src/service/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { getCache, setCache } from '../utils/persistentCache.js';
import { getFileHash } from '../utils/hash.js';
import dynamicImport from '../utils/dynamicImport.js';
import formatPath from '../utils/formatPath.js';
import { RUNTIME_TMP_DIR } from '../constant.js';
import { RUNTIME_TMP_DIR, CACHE_DIR } from '../constant.js';

type GetOutfile = (entry: string, exportNames: string[]) => string;

Expand Down Expand Up @@ -115,7 +115,7 @@ export const getAppExportConfig = (rootDir: string) => {
}
const appEntry = path.join(rootDir, 'src/app');
const getOutfile = (entry: string, keepExports: string[]) =>
formatPath(path.join(rootDir, 'node_modules', `${keepExports.join('_')}_${path.basename(entry)}.mjs`));
formatPath(path.join(rootDir, CACHE_DIR, `${keepExports.join('_')}_${path.basename(entry)}.mjs`));
const config = new Config({
entry: appEntry,
rootDir,
Expand Down
4 changes: 2 additions & 2 deletions packages/ice/src/service/preBundleCJSDeps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import flattenId from '../utils/flattenId.js';
import formatPath from '../utils/formatPath.js';
import { BUILDIN_CJS_DEPS, BUILDIN_ESM_DEPS } from '../constant.js';
import type { DepScanData } from '../esbuild/scan.js';
import aliasPlugin from '../esbuild/alias.js';
import resolvePlugin from '../esbuild/resolve.js';
import emptyCSSPlugin from '../esbuild/emptyCSS.js';
import cssModulesPlugin from '../esbuild/cssModules.js';
import escapeLocalIdent from '../utils/escapeLocalIdent.js';
Expand Down Expand Up @@ -96,7 +96,7 @@ export default async function preBundleCJSDeps(options: PreBundleDepsOptions): P
ignoreAnnotations: true,
plugins: [
emptyCSSPlugin(),
aliasPlugin({ alias, format: 'cjs', externalDependencies: false }),
resolvePlugin({ alias, format: 'cjs', externalDependencies: false }),
cssModulesPlugin({
extract: false,
generateLocalIdentName: function (name: string, filename: string) {
Expand Down
Loading

0 comments on commit 3d8bcff

Please sign in to comment.