Skip to content

Commit d233142

Browse files
committed
Install dart-sass dev snapshot as npm module
1 parent 6ca7947 commit d233142

File tree

3 files changed

+35
-56
lines changed

3 files changed

+35
-56
lines changed

.github/workflows/ci.yml

+1-11
Original file line numberDiff line numberDiff line change
@@ -117,17 +117,7 @@ jobs:
117117
working-directory: sass-spec
118118

119119
- name: Compile
120-
run: |
121-
npm run compile
122-
if [[ "$RUNNER_OS" == "Windows" ]]; then
123-
# Avoid copying the entire Dart Sass build directory on Windows,
124-
# since it may contain symlinks that cp will choke on.
125-
mkdir -p dist/lib/src/vendor/dart-sass/
126-
cp {`pwd`/,dist/}lib/src/vendor/dart-sass/sass.bat
127-
cp {`pwd`/,dist/}lib/src/vendor/dart-sass/sass.snapshot
128-
else
129-
ln -s {`pwd`/,dist/}lib/src/vendor/dart-sass
130-
fi
120+
run: npm run compile
131121

132122
- name: Run tests
133123
run: npm run js-api-spec -- --sassPackage .. --sassSassRepo ../language

lib/src/compiler-path.ts

+18-29
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22
// MIT-style license that can be found in the LICENSE file or at
33
// https://opensource.org/licenses/MIT.
44

5-
import * as fs from 'fs';
65
import * as p from 'path';
76
import {getElfInterpreter} from './elf';
8-
import {isErrnoException} from './utils';
97

108
/**
119
* Detect if the given binary is linked with musl libc by checking if
@@ -23,51 +21,43 @@ function isLinuxMusl(path: string): boolean {
2321
}
2422
}
2523

26-
/** The full command for the embedded compiler executable. */
27-
export const compilerCommand = (() => {
24+
/** The module name for the embedded compiler executable. */
25+
export const compilerModule = (() => {
2826
const platform =
2927
process.platform === 'linux' && isLinuxMusl(process.execPath)
3028
? 'linux-musl'
3129
: (process.platform as string);
3230

3331
const arch = process.arch;
3432

35-
// find for development
36-
for (const path of ['vendor', '../../../lib/src/vendor']) {
37-
const executable = p.resolve(
38-
__dirname,
39-
path,
40-
`dart-sass/sass${platform === 'win32' ? '.bat' : ''}`
41-
);
42-
43-
if (fs.existsSync(executable)) return [executable];
44-
}
33+
return `sass-embedded-${platform}-${arch}`;
34+
})();
4535

36+
/** The full command for the embedded compiler executable. */
37+
export const compilerCommand = (() => {
4638
try {
4739
return [
4840
require.resolve(
49-
`sass-embedded-${platform}-${arch}/dart-sass/src/dart` +
50-
(platform === 'win32' ? '.exe' : '')
51-
),
52-
require.resolve(
53-
`sass-embedded-${platform}-${arch}/dart-sass/src/sass.snapshot`
41+
`${compilerModule}/dart-sass/src/dart` +
42+
(process.platform === 'win32' ? '.exe' : '')
5443
),
44+
require.resolve(`${compilerModule}/dart-sass/src/sass.snapshot`),
5545
];
5646
} catch (e) {
57-
if (!(isErrnoException(e) && e.code === 'MODULE_NOT_FOUND')) {
47+
if (e.code !== 'MODULE_NOT_FOUND') {
5848
throw e;
5949
}
6050
}
6151

6252
try {
6353
return [
6454
require.resolve(
65-
`sass-embedded-${platform}-${arch}/dart-sass/sass` +
66-
(platform === 'win32' ? '.bat' : '')
55+
`${compilerModule}/dart-sass/sass` +
56+
(process.platform === 'win32' ? '.bat' : '')
6757
),
6858
];
69-
} catch (e: unknown) {
70-
if (!(isErrnoException(e) && e.code === 'MODULE_NOT_FOUND')) {
59+
} catch (e) {
60+
if (e.code !== 'MODULE_NOT_FOUND') {
7161
throw e;
7262
}
7363
}
@@ -77,16 +67,15 @@ export const compilerCommand = (() => {
7767
process.execPath,
7868
p.join(p.dirname(require.resolve('sass')), 'sass.js'),
7969
];
80-
} catch (e: unknown) {
81-
if (!(isErrnoException(e) && e.code === 'MODULE_NOT_FOUND')) {
70+
} catch (e) {
71+
if (e.code !== 'MODULE_NOT_FOUND') {
8272
throw e;
8373
}
8474
}
8575

8676
throw new Error(
8777
"Embedded Dart Sass couldn't find the embedded compiler executable. " +
88-
'Please make sure the optional dependency ' +
89-
`sass-embedded-${platform}-${arch} or sass is installed in ` +
90-
'node_modules.'
78+
`Please make sure the optional dependency ${compilerModule} or sass is ` +
79+
'installed in node_modules.'
9180
);
9281
})();

tool/get-embedded-compiler.ts

+16-16
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
// MIT-style license that can be found in the LICENSE file or at
33
// https://opensource.org/licenses/MIT.
44

5-
import {promises as fs, readdirSync} from 'fs';
5+
import {promises as fs} from 'fs';
66
import * as p from 'path';
77
import * as shell from 'shelljs';
88

9+
import {compilerModule} from '../lib/src/compiler-path';
910
import * as utils from './utils';
1011

1112
/**
@@ -44,24 +45,23 @@ export async function getEmbeddedCompiler(
4445
}
4546

4647
buildDartSassEmbedded(source, js ?? false);
48+
49+
const jsModulePath = p.resolve('node_modules/sass');
50+
const dartModulePath = p.resolve(p.join('node_modules', compilerModule));
4751
if (js) {
48-
// Remove sass-embedded-* packages
49-
const modules = ['node_modules', p.join(source, 'node_modules')].flatMap(
50-
node_modules =>
51-
readdirSync(node_modules)
52-
.filter(dir => dir.startsWith('sass-embedded-'))
53-
.map(dir => p.join(node_modules, dir))
54-
);
55-
if (modules.length > 0) {
56-
console.log(`Removing ${modules.join(', ')}.`);
57-
await Promise.all(
58-
modules.map(module => fs.rm(module, {force: true, recursive: true}))
59-
);
60-
}
52+
// The next line is only needed temporarily because sass local dev
53+
// package.json currently installs sass-embedded for sync-message-port.js
54+
// https://github.com/sass/dart-sass/pull/2413
55+
await fs.rm(p.join(source, 'node_modules', compilerModule), {
56+
force: true,
57+
recursive: true,
58+
});
6159

62-
await utils.link(p.join(source, 'build/npm'), 'node_modules/sass');
60+
await fs.rm(dartModulePath, {force: true, recursive: true});
61+
await utils.link(p.join(source, 'build/npm'), jsModulePath);
6362
} else {
64-
await utils.link(p.join(source, 'build'), p.join(outPath, repo));
63+
await fs.rm(jsModulePath, {force: true, recursive: true});
64+
await utils.link(p.join(source, 'build'), p.join(dartModulePath, repo));
6565
}
6666
}
6767

0 commit comments

Comments
 (0)