Skip to content
This repository was archived by the owner on Jul 6, 2025. It is now read-only.

Commit a868aad

Browse files
committed
Merge branch 'master' into feat-0.3-beta
2 parents 83ab913 + c43f951 commit a868aad

File tree

5 files changed

+75
-24
lines changed

5 files changed

+75
-24
lines changed

commands/helpers/is-folder-empty.ts

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { green, blue } from 'https://deno.land/[email protected]/fmt/colors.ts'
2+
import { join } from "https://deno.land/std/path/mod.ts"
3+
4+
export default function (root: string, name: string): boolean {
5+
const validFiles = [
6+
'.DS_Store',
7+
'.git',
8+
'.gitattributes',
9+
'.gitignore',
10+
'.gitlab-ci.yml',
11+
'.hg',
12+
'.hgcheck',
13+
'.hgignore',
14+
'.idea',
15+
'.travis.yml',
16+
'LICENSE',
17+
'Thumbs.db',
18+
'docs',
19+
'mkdocs.yml',
20+
]
21+
22+
const conflicts = []
23+
24+
for (const { name: file } of Deno.readDirSync(root)) {
25+
// Support IntelliJ IDEA-based editors
26+
if (validFiles.includes(file) || /\.iml$/.test(file)) {
27+
conflicts.push(file)
28+
}
29+
}
30+
31+
if (conflicts.length > 0) {
32+
console.log(
33+
`The directory ${green(name)} contains files that could conflict:`
34+
)
35+
console.log()
36+
37+
for (const file of conflicts) {
38+
try {
39+
const stats = Deno.lstatSync(join(root, file))
40+
if (stats.isDirectory) {
41+
console.log(` ${blue(file)}/`)
42+
} else {
43+
console.log(` ${file}`)
44+
}
45+
} catch {
46+
console.log(` ${file}`)
47+
}
48+
}
49+
50+
console.log()
51+
console.log(
52+
'Either try using a new directory name, or remove the files listed above.'
53+
)
54+
console.log()
55+
56+
return false
57+
}
58+
59+
return true
60+
61+
}

commands/init.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import util from '../shared/util.ts'
88
import { defaultReactVersion } from '../shared/constants.ts'
99
import { VERSION } from '../version.ts'
1010
import { deno_x_brotli, deno_x_flate } from '../server/compress.ts'
11+
import isFolderEmpty from './helpers/is-folder-empty.ts';
1112

1213
export const helpMessage = `
1314
Usage:
@@ -28,6 +29,10 @@ export default async function (nameArg?: string) {
2829
return
2930
}
3031

32+
if (!isFolderEmpty(cwd, name)) {
33+
Deno.exit(1)
34+
}
35+
3136
const template = 'hello-world' // todo: add template select ui
3237
const vscode = await confirm('Add recommended workspace settings of VS Code?')
3338

framework/react/helper.ts

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,10 @@ const REACT_MEMO_TYPE = symbolFor ? Symbol.for('react.memo') : 0xead3
66

77
export const inDeno = typeof Deno !== 'undefined' && typeof Deno.version?.deno === 'string'
88

9-
export function isLikelyReactComponent(type: any, strict = true): Boolean {
9+
export function isLikelyReactComponent(type: any): Boolean {
1010
switch (typeof type) {
1111
case 'function':
12-
if (type.prototype != null) {
13-
if (type.prototype.isReactComponent) {
14-
return true
15-
}
16-
const ownNames = Object.getOwnPropertyNames(type.prototype)
17-
if (ownNames.length > 1 || ownNames[0] !== 'constructor') {
18-
return false
19-
}
20-
}
21-
if (!strict) {
22-
// don't check component name
23-
return true
24-
}
25-
const { __ALEPH__: ALEPH } = window as any
26-
if (ALEPH) {
27-
// in bundle mode, the component names have been compressed.
28-
return true
29-
}
30-
const name = type.displayName || type.name
31-
return typeof name === 'string' && /^[A-Z]/.test(name)
12+
return true
3213
case 'object':
3314
if (type != null) {
3415
switch (type.$$typeof) {

server/helper.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ export function getSourceType(url: string, contentType?: string): SourceType {
148148
return SourceType.Unknown
149149
}
150150

151+
const reEndsWithVersion = /@\d+(\.\d+){0,2}(\-[a-z0-9]+(\.[a-z0-9]+)?)?$/
152+
151153
/**
152154
* fix remote import url to local
153155
* https://esm.sh/react.js?bundle -> /-/esm.sh/react.YnVuZGxl.js
@@ -162,9 +164,10 @@ export function toLocalPath(url: string): string {
162164
if (search !== '') {
163165
const a = util.splitPath(pathname)
164166
const basename = a.pop()!
165-
const ext = extname(basename)
167+
const realext = extname(basename)
168+
const ext = realext != "" && !basename.match(reEndsWithVersion) ? realext : "js"
166169
const search64 = util.btoaUrl(search.slice(1))
167-
a.push(util.trimSuffix(basename, ext) + `.${search64}` + ext)
170+
a.push(util.trimSuffix(basename, ext) + `.${search64}.` + ext)
168171
pathname = '/' + a.join('/')
169172
}
170173
return [

server/helper_test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ Deno.test('server/helper: toRelativePath', () => {
2929
})
3030

3131
Deno.test('server/helper: toLocalPath', () => {
32+
assertEquals(toLocalPath('https://foo.com/[email protected]?action'), `/-/foo.com/[email protected].${util.btoaUrl('action')}.js`)
3233
assertEquals(toLocalPath('https://deno.land/x/[email protected]/'), '/-/deno.land/x/[email protected]/')
33-
assertEquals(toLocalPath('http://foo.com/bar?lang=us-en'), `/-/http_foo.com/bar.${util.btoaUrl('lang=us-en')}`)
34+
assertEquals(toLocalPath('http://foo.com/bar?lang=us-en'), `/-/http_foo.com/bar.${util.btoaUrl('lang=us-en')}.js`)
3435
assertEquals(toLocalPath('http://foo.com:8080/bar'), '/-/http_foo.com_8080/bar')
3536
assertEquals(toLocalPath('file://foo/bar/'), 'foo/bar/')
3637
assertEquals(toLocalPath('/foo/bar/'), '/foo/bar/')

0 commit comments

Comments
 (0)