Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export function parseArgs(argv: string[]) {
'tmpdir',
],
default: {
asar: true,
junk: true,
prune: true,
tmpdir: true,
Expand Down
15 changes: 11 additions & 4 deletions src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,22 @@ export function subOptionWarning(
properties[parameter] = value;
}

/**
* Creates the final `@electron/asar` options for final packaging function based on user options.
* @param opts The processed options for the packager.
* @returns The ASAR options or false if ASAR is disabled.
*/
export function createAsarOpts(
opts: ProcessedOptionsWithSinglePlatformArch,
): false | AsarOptions {
let asarOptions;
if (opts.asar === true) {
asarOptions = {};
let asarOptions: AsarOptions;
if (opts.asar === true || opts.asar === undefined) {
asarOptions = {
unpack: '**/{.**,**}/**/*.node',
};
} else if (typeof opts.asar === 'object') {
asarOptions = opts.asar;
} else if (opts.asar === false || opts.asar === undefined) {
} else if (opts.asar === false) {
return false;
} else {
warning(
Expand Down
4 changes: 2 additions & 2 deletions src/platform.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'graceful-fs';
import path from 'node:path';
import {
createPackageWithOptions,
createPackageWithOptions as createASARWithOptions,
FileRecord,
getRawHeader,
} from '@electron/asar';
Expand Down Expand Up @@ -340,7 +340,7 @@ export class App {
this.hookArgsWithOriginalResourcesAppDir,
);

await createPackageWithOptions(
await createASARWithOptions(
this.originalResourcesAppDir,
this.appAsarPath,
this.asarOptions,
Expand Down
25 changes: 15 additions & 10 deletions test/common.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,21 +130,26 @@ describe('validateElectronApp', () => {
});

describe('createAsarOpts', () => {
it('returns false if asar is not set', () => {
expect(createAsarOpts({} as ProcessedOptionsWithSinglePlatformArch)).toBe(
false,
);
it('unpacks native node modules if true', () => {
expect(
createAsarOpts({ asar: true } as ProcessedOptionsWithSinglePlatformArch),
).toEqual({
unpack: '**/{.**,**}/**/*.node',
});
});
it('returns false if asar is false', () => {

it('returns true if asar is not set', () => {
expect(
createAsarOpts({ asar: false } as ProcessedOptionsWithSinglePlatformArch),
).toBe(false);
createAsarOpts({} as ProcessedOptionsWithSinglePlatformArch),
).toEqual({
unpack: '**/{.**,**}/**/*.node',
});
});

it('sets asar options to {} if true', () => {
it('returns false if asar is false', () => {
expect(
createAsarOpts({ asar: true } as ProcessedOptionsWithSinglePlatformArch),
).toEqual({});
createAsarOpts({ asar: false } as ProcessedOptionsWithSinglePlatformArch),
).toBe(false);
});

it('sets asar options to the value if it is an object', () => {
Expand Down
35 changes: 6 additions & 29 deletions test/packager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,33 +92,7 @@ describe('packager', () => {
),
).toBe(false);

// packages main.js
const inputMain = path.join(__dirname, 'fixtures', 'basic', 'main.js');
const outputMain = path.join(resourcesPath, 'app', 'main.js');

expect(fs.readFileSync(inputMain, 'utf8')).toEqual(
fs.readFileSync(outputMain, 'utf8'),
);

// packages subdirectory resources
const inputResource = path.join(
__dirname,
'fixtures',
'basic',
'ignore',
'this.txt',
);
const outputResource = path.join(
resourcesPath,
'app',
'ignore',
'this.txt',
);

expect(fs.readFileSync(inputResource, 'utf8')).toEqual(
fs.readFileSync(outputResource, 'utf8'),
);

expect(fs.existsSync(path.join(resourcesPath, 'app.asar'))).toBe(true);
expect(fs.existsSync(path.join(resourcesPath, 'default_app'))).toBe(false);
expect(fs.existsSync(path.join(resourcesPath, 'default_app.asar'))).toBe(
false,
Expand Down Expand Up @@ -213,6 +187,7 @@ describe('packager', () => {
derefSymlinks: false,
platform: 'linux',
arch: 'x64',
asar: false,
} as const;

const src = path.join(opts.dir, 'main.js');
Expand Down Expand Up @@ -569,19 +544,19 @@ describe('packager', () => {
'beforeCopy',
'afterCopy',
'afterPrune',
'afterAsar',
'afterInitialize',
'afterComplete',
],
},
{
testOpts: { asar: true },
testOpts: { asar: false },
expectedOutput: [
'afterFinalizePackageTargets',
'afterExtract',
'beforeCopy',
'afterCopy',
'afterPrune',
'afterAsar',
'afterInitialize',
'afterComplete',
],
Expand All @@ -593,6 +568,7 @@ describe('packager', () => {
'afterExtract',
'beforeCopy',
'afterCopy',
'afterAsar',
'afterInitialize',
'afterComplete',
],
Expand Down Expand Up @@ -717,6 +693,7 @@ describe('packager', () => {
}) => {
const opts = {
...baseOpts,
asar: false,
};

const paths = await packager(opts);
Expand Down
2 changes: 1 addition & 1 deletion usage.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ arch all, or one or more of: ia32, x64, armv7l, arm64, mips64el, u
asar whether to package the source code within your app into an archive. You can either
pass --asar by itself to use the default configuration, OR use dot notation to
configure a list of sub-properties, e.g. --asar.unpackDir=sub_dir - do not use
--asar and its sub-properties simultaneously.
--asar and its sub-properties simultaneously. Defaults to `true`.

Properties supported include:
- ordering: path to an ordering file for file packing
Expand Down