Skip to content

Commit

Permalink
feat: reduce dependents size & upgrade core version & optimzie entry … (
Browse files Browse the repository at this point in the history
  • Loading branch information
shulandmimi committed Jun 21, 2024
1 parent 789e22b commit 5806b18
Show file tree
Hide file tree
Showing 31 changed files with 201 additions and 234 deletions.
5 changes: 5 additions & 0 deletions .changeset/afraid-weeks-jam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'farmup': patch
---

reduce dependents size & upgrade core version & optimzie entry find
5 changes: 4 additions & 1 deletion biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
"style": {
"noNonNullAssertion": "off"
}
}
},
"ignore": [
"dist"
]
},
"javascript": {
"formatter": {
Expand Down
67 changes: 14 additions & 53 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,65 +1,26 @@
{
"name": "farmup",
"version": "0.0.11",
"version": "0.0.0",
"description": "",
"private": true,
"type": "module",
"repository": {
"url": "https://github.com/farm-fe/farmup"
},
"publishConfig": {
"access": "public"
},
"scripts": {
"dev": "farm watch",
"build": "farm build",
"preview": "farm preview",
"clean": "farm clean",
"release": "pnpm run build && changeset publish",
"farmup": "node ./bin/farmup.js --no-exec -w",
"ready": "node ./bin/farmup.js ./scripts/ready.ts -o ./dist/ready --no-config"
},
"bin": {
"farmup": "./bin/farmup.js"
},
"devDependencies": {
"@biomejs/biome": "^1.7.3",
"@farmfe/cli": "^1.0.2",
"@types/fs-extra": "^11.0.4",
"@types/lodash-es": "^4.17.12",
"@types/node": "^20.12.7",
"@types/tmp": "^0.2.6",
"chokidar": "^3.6.0",
"execa": "^8.0.1",
"typescript": "^5.4.5"
},
"exports": {
".": {
"import": "./dist/index.js",
"require": "./dist/index.js",
"types": "./dist/index.d.ts"
},
"./plugin": {
"import": "./dist/plugin.js",
"types": "./dist/plugin.d.ts"
}
"release": "pnpm --filter './packages/*' run build && changeset publish",
"ready": "farmup ./scripts/ready.ts -o ./dist/ready --no-config"
},
"author": {
"name": "shulandmimi",
"email": "[email protected]"
},
"keywords": [],
"license": "MIT",
"dependencies": {
"@changesets/cli": "^2.27.3",
"@farmfe/core": "^1.1.12",
"cac": "^6.7.14",
"cspell": "^8.8.3",
"fs-extra": "^11.2.0",
"glob": "^10.3.15",
"lodash-es": "^4.17.21",
"open": "^10.1.0",
"tmp": "^0.2.3"
"farmup": "workspace:*"
},
"files": [
"dist",
"README.md",
"bin"
]
"devDependencies": {
"@biomejs/biome": "^1.7.3",
"cspell": "^8.8.3",
"execa": "^8.0.1",
"@changesets/cli": "^2.27.3"
}
}
File renamed without changes.
3 changes: 2 additions & 1 deletion farm.config.ts → packages/core/farm.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ export default defineConfig({
},
output: {
targetEnv: 'node',
format: 'esm'
format: 'esm',
},
persistentCache: false,
external: ['^@farmfe/core$'],
minify: false,
treeShaking: true,
},
});
58 changes: 58 additions & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"name": "farmup",
"version": "0.0.11",
"type": "module",
"repository": {
"url": "https://github.com/farm-fe/farmup"
},
"scripts": {
"dev": "farm watch",
"build": "farm build",
"preview": "farm preview",
"clean": "farm clean",
"farmup": "node ./bin/farmup.js --no-exec -w"
},
"bin": "./bin/farmup.js",
"devDependencies": {
"@farmfe/cli": "^1.0.2",
"@types/fs-extra": "^11.0.4",
"@types/lodash-es": "^4.17.12",
"@types/node": "^20.12.7",
"typescript": "^5.4.5",
"cac": "^6.7.14",
"execa": "^8.0.1",
"fs-extra": "^11.2.0",
"glob": "^10.3.15",
"lodash-es": "^4.17.21"
},
"exports": {
".": {
"import": "./dist/index.js",
"require": "./dist/index.js",
"types": "./dist/index.d.ts"
},
"./plugin": {
"import": "./dist/plugin.js",
"types": "./dist/plugin.d.ts"
}
},
"keywords": [
"farm",
"cli",
"execute",
"exec",
"typescript",
"html",
"javascript",
"ts",
"js",
"builder"
],
"author": {
"name": "shulandmimi",
"email": "[email protected]"
},
"dependencies": {
"@farmfe/core": "^1.2.0"
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -151,18 +151,19 @@ export function pinOutputEntryFilename(options: ResolvedCommonOptions) {

const executeMode = options.execute.type;

function matchEntryName(name: string, inputs: Record<string, string>) {
const inputNameKey = name.split('.').slice(0, -1).join('.');

if (Object.hasOwn(inputs, inputNameKey)) {
return name;
}
if(options.target?.startsWith('browser')) {
return;
}

if (executeMode === ExecuteMode.Custom || executeMode === ExecuteMode.Node) {
if ((executeMode === ExecuteMode.Custom || executeMode === ExecuteMode.Node) && !options.noExecute) {
options.entry = Object.entries(options.entry).reduce((res, [key, val]) => {
res[`${key}.${formatMapExt[options.format ?? 'cjs']}`] = val;
return res;
}, {} as Record<string, string>);

options.outputEntry = {
matchEntryName,
name: `[entryName].${formatMapExt[options.format ?? 'cjs']}`,
name: '[entryName]'
};
}
}
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export class ProxyCompiler {

private event: EventEmitter = new EventEmitter();

private lastResources: string[] = [];
private _preProxyFnList: (keyof Compiler)[] = [];
private alreadyProxyFnList: Set<keyof Compiler> = new Set();

Expand All @@ -31,14 +30,6 @@ export class ProxyCompiler {
this.proxyCompiler(fnName);
}
}

this.on('resources', (r) => {
this.lastResources = Object.keys(r.result);
});
}

get resource_names() {
return this.lastResources;
}

private proxyCompiler<K extends keyof Compiler>(fnName: K) {
Expand All @@ -64,7 +55,7 @@ export class ProxyCompiler {
OFT extends Record<keyof T, (...args: any) => any> = {
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
[KK in keyof T]: T[KK] extends (...args: any[]) => any ? T[KK] : never;
}
},
>(fnName: K, fn: (context: FnContext<Parameters<OFT[K]>, ReturnType<OFT[K]>>) => void) {
this.proxyCompiler(fnName as keyof Compiler);
this.event.on(fnName.toString(), fn);
Expand Down
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions src/index.ts → packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ function createInlineConfig(options: CommonOptions): InlineConfig {
async function autoStart(options: CommonOptions) {
const preNormalizeOption = await NormalizeOption.fromCommonOption(options, new NoopLogger());
const inlineConfig = createInlineConfig(options);
// console.log(preNormalizeOption.options);
switch (preNormalizeOption.options.execute.type) {
case ExecuteMode.Browser:
return farmStart(inlineConfig);
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,13 @@ export default function autoExecute(options: CommonOptions = {}, logger = defaul
return;
}

const resourceOutputEntryFormatter = normalizeOption.options.outputEntry;
const resourceOutputEntry = proxyCompiler.resource_names.find((item) =>
resourceOutputEntryFormatter.matchEntryName(item, normalizeOption.options.entry),
);
const resourceOutputEntry = Object.keys(normalizeOption.options.entry)[0];

if (!resourceOutputEntry) {
logger.error('output entry is not found');
return;
}

// TODO: multiple entry
const executePath = path.join(outputDir, resourceOutputEntry);

if (!executer) {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ export interface ResolvedCommonOptions {
noWatch?: boolean;

outputEntry?: {
matchEntryName: (name: string, inputs: Record<string, string>) => string | undefined;
name: string;
};

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 6 additions & 0 deletions packages/core/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "../../tsconfig.json",
"include": [
"src"
]
}
6 changes: 6 additions & 0 deletions packages/core/tsconfig.node.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "../../tsconfig.node.json",
"include": [
"./farm.config.ts"
]
}
Loading

0 comments on commit 5806b18

Please sign in to comment.